Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/383.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在播放音频后,如何取消激活IE中的播放按钮?_Javascript_Html_Onclick_Html5 Audio - Fatal编程技术网

Javascript 在播放音频后,如何取消激活IE中的播放按钮?

Javascript 在播放音频后,如何取消激活IE中的播放按钮?,javascript,html,onclick,html5-audio,Javascript,Html,Onclick,Html5 Audio,以下代码适用于除IE之外的所有其他浏览器,在IE中,一旦播放音频并显示“下一步”按钮,您仍然可以单击音频并再次听到它。由于这是一项调查,如果有人能多次听到,对参与者来说是不公平的。你能告诉我为什么它在其他浏览器中工作正常,但在IE中却不正常,以及如何修复它吗? 我希望用户在“单击继续”按钮出现后不能再次听到(即使他们单击“播放故事”按钮) Now that you know how the auditory stories will sound, you are ready to listen

以下代码适用于除IE之外的所有其他浏览器,在IE中,一旦播放音频并显示“下一步”按钮,您仍然可以单击音频并再次听到它。由于这是一项调查,如果有人能多次听到,对参与者来说是不公平的。你能告诉我为什么它在其他浏览器中工作正常,但在IE中却不正常,以及如何修复它吗?

我希望用户在“单击继续”按钮出现后不能再次听到(即使他们单击“播放故事”按钮)

Now that you know how the auditory stories will sound, you are ready to listen to and comprehend the two auditory stories in this study. The first auditory story is titled, “The Honey Gatherer’s Three Sons.” Press the “Play Story” button to begin listening to the story; after you have finished listening to the story, you will answer a set of questions about the story.
<div>&nbsp;
<p>&nbsp;</p>

<audio controls="" id="audio2" style="display:none"><source src="http://langcomplab.net/Honey_Gatherers_Master.webm" style="width:50%" type="audio/webm" /> <source src="http://langcomplab.net/Honey_Gatherers_Master.mp3" style="width:50%" type="audio/mp3" /> Your browser doesn&#39;t support this audio format.</audio>
</div>

<p>&nbsp;</p>

<div><button name="play" onclick="disabled=true" style="height:25px; width:200px" type="button">Play Story</button></div>
更新:我在HTML中将其更改为以下内容:

<div><button name="play" style="width: 200px; height: 25px;" type="button">Play Story</button>

但是,在播放音频并显示“继续”按钮后,用户可以在IE中单击“播放故事”按钮并再次听到它,而在其他浏览器中则不会出现这种情况。JavaScript或HTML5中是否有任何选项可以避免用户在播放音频后播放该音频,这对IE来说是可行的?

我不确定IE为什么没有做到你想要的,但我想人们永远不会真正理解IE为什么会做出这样的响应

但是,您可能希望在questionClick函数中组合这两个操作。(可能onClick事件处理程序会停止触发onClick属性) 例如:

Qualtrics.SurveyEngine.addOnload(function()
{
    /*Place Your Javascript Below This Line*/
    var aud = document.getElementById('audio2');
    this.questionclick = function(event,element){

        if((element.type == "button") && (element.name == "play"))
        {
            aud.play();
            // remove the element
            element.parentNode.removeChild(element);
            // or set it to disabled, what you like
            element.disabled = true;
        }

    }


});
不要忘记从按钮中删除onClick属性:

<div><button name="play" style="height:25px; width:200px" type="button">Play Story</button></div>

什么版本的IE不起作用?IE11 for Win7不起作用您使用什么代码将侦听器函数绑定到click事件?我正在使用qualtrics,只需要在js中传递我添加的正确音频。我不确定它是否完全正确,但它在其他浏览器中工作正常。你能再解释一下你说的吗?很难说是什么导致了这个问题,因为我看不到所有的代码。尝试从按钮中删除
disabled=true
,并在JS中添加
element.disabled=true
后立即添加
aud.play()
Qualtrics.SurveyEngine.addOnload(function()
{
    /*Place Your Javascript Below This Line*/
    var aud = document.getElementById('audio2');
    this.questionclick = function(event,element){

        if((element.type == "button") && (element.name == "play"))
        {
            aud.play();
            // remove the element
            element.parentNode.removeChild(element);
            // or set it to disabled, what you like
            element.disabled = true;
        }

    }


});
<div><button name="play" style="height:25px; width:200px" type="button">Play Story</button></div>
// Set a variable
var hasPlayed = false;
Qualtrics.SurveyEngine.addOnload(function()
{
    /*Place Your Javascript Below This Line*/
    var aud = document.getElementById('audio2');
    this.questionclick = function(event,element){

        if((element.type == "button") && (element.name == "play"))
        {
            // Check if audio hasn't played before
            if(hasPlayed == false) aud.play();
            // Flip the variable to make sure it won't play on next click
            hasPlayed = true;
        }

    }


});