使用PHP站点发布javascript代码并翻译代码,结果代码不起作用



我有一个php站点,它允许嵌入javascript。我有一个函数在IE或chrome中无法正常工作。你能看一看,告诉我是否有问题吗

 <script language="javascript" type="text/javascript">
//<![CDATA[
var counting = 0;
var totaltime;
var audio;
var timeout;
var settimer = 0;
var haystack = "|";
var needle;
function start_playing(a,b){ haystack = haystack+a+"|";
needle = a;
audio = document.getElementById(b);counting = counting + 1.0;   audio.play();
if(haystack.split(needle).length -1 >= 2){document.getElementById(a).value = "No Plays  Left";
document.getElementById(a).disabled = true;}else{document.getElementById(a).value = "Playing";
document.getElementById(a).disabled = true;totaltime = Math.round(audio.duration)*1000;
timeout = setTimeout("enable_button('"+a+"')",totaltime);}}function enable_button(a)   {document.getElementById(a).value ="Play"document.getElementById(a).disabled = false;}}
//]]>
</script>
<div>
<input id="PlayButton1" type="button" onclick="start_playing('PlayButton1','myTune1')" value="Play" /></div>
<audio id="myTune1" src="sound.mp3" type="audio/mp3"></audio>

问题出在哪里?。它应该被点击,在歌曲的持续时间内禁用,然后启用它自己。在第二场比赛之后,它会说没有比赛了。

我已经修改了您的代码。这应该工作

<script language="javascript" type="text/javascript">
//<![CDATA[
var counting = 0;
var totaltime;
var audio;
var timeout;
function start_playing(a,b){ 
    audio = document.getElementById(b);
    counting++;
    audio.play();
    if(counting == 2){
        document.getElementById(a).value = "No Plays Left";
        document.getElementById(a).disabled = true;
    }else{
        document.getElementById(a).value = "Playing";
        document.getElementById(a).disabled = true;
        totaltime = Math.round(audio.duration)*1000;
        timeout = setTimeout("enable_button('"+a+"')",totaltime);
    }
}
function enable_button(a){
    document.getElementById(a).value = "Play";
    document.getElementById(a).disabled = false;
}
//]]>
</script>
<div>
<input id="PlayButton1" type="button" onclick="start_playing('PlayButton1','myTune1')" value="Play" /></div>
<audio id="myTune1" src="sound.mp3" type="audio/mp3"></audio>

但是仍然有未使用的变量。请在下次提交答案之前格式化您的代码。

最新更新