2013-12-18 52 views
-1

我有这个小脚本,假设有人已经播放了超过27秒的音频文件,可以对表进行+1。脚本变成白色页

用于正常工作的代码,直到我的主机被黑客入侵,我的代码被混淆。

现在我不知道它有什么问题。
我不擅长jQuery。我查阅了一些教程并做了大量的猜测,所以我可以得到这段代码的工作。

$(document).ready(function() { 

    $("#audio").bind('play', function() { 
     document.clock.theButton.value = "Stop"; 
     stopwatch(this.value); 
    }); 

    $("#audio").bind('pause', function() { 
     document.clock.theButton.value = "Start"; 
    }); 

}); 

var sec = -1; 

function stopwatch(text) { 
    sec++; 
    if (sec <= 9) { 
     sec = "0" + sec; 
    } 
    document.clock.stwa.value = sec; 

    if (document.clock.stwa.value == "27") { 
     $("#play").load("<?php echo 'accounts.php?id={$id}&music={$music}&add_play=1'; ?>"); 
    } 
    if (document.clock.theButton.value == "Start") { 
     window.clearTimeout(SD); 
     sec = sec - 1; 
     return true; 
    } 
    SD = window.setTimeout("stopwatch();", 1000); 
} 

$(document).ready(function() { 
    $("#audio").bind('ended', function() { 
     sec = -1; 
    }); 
}); 

,我发现了以下错误:

Uncaught ReferenceError: $ is not defined popup.js:1 Failed to load resource box.anchorfree.net/insert/41.js?v=413161526
Uncaught TypeError: Cannot read property 'stwa' of undefined

*编辑*

我已经按照你的反应更新的代码和我” m仍然有问题,它的部分是假设加载页面。我已经改变了这部分,并添加了一个警告,所以我可以确保没有错误的PHP页面,但我甚至没有得到警报显示。

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"> 

<script language="JavaScript" type="text/javascript"> 
    $(document).ready(function(){ 

    $("#audio").bind('play', function(){ 
document.clock.theButton.value = "Stop"; 
stopwatch(this.value); 
    }); 

    $("#audio").bind('pause', function(){ 
document.clock.theButton.value = "Start"; 
    }); 

}); 

var sec = -1; 
function stopwatch(text) { 
    sec++; 
if (sec<=9) { sec = 0 + sec; } 
    document.clock.stwa.value = sec; 


    if(document.clock.stwa.value=="27"){ 
alert("Worked"); 
} 
    if (document.clock.theButton.value == "Start") { 
    window.clearTimeout(SD); 
    sec=sec-1; 
    return true; } 
SD = window.setTimeout(stopwatch, 1000); 
} 
$(document).ready(function(){ 

    $("#audio").bind('ended', function(){ 
    sec=-1; 
    }); 
}); 


</script> 
<form name="clock" style="display:none;"><br /> 
     <input type="text" size="12" name="stwa" id="stwa" /><br /> 
     <input type="button" name="theButton" onClick="stopwatch(this.value);" value="Start" /> 
     <input type="button" value="Reset" onClick="resetIt();reset();" /> 
     </form> 
+3

白色页面可能是由于一个JS错误。浏览器控制台中显示了什么? – isherwood

+0

Uncaught ReferenceError:$未定义popup.js:1 未能加载资源http://box.anchorfree.net/insert/41.js?v=413161526 未捕获TypeError:无法读取未定义的属性'stwa' –

+2

jquery没有链接到页面 –

回答

-1

1 - 连结的jQuery到页面

2 - 替换document.clock.stwa.value = sec;

document.clock.stwa.value = parseInt(sec);

3 - 更换SD = window.setTimeout("stopwatch();", 1000);

SD = window.setTimeout(stopwatch(), 1000);

4 - 检查在HTML如果任何输入被定义用id“stwa”和“theButton”形式“时钟”的内部,这样的:

<form name="clock"> 
    <input type="text" id="stwa" name="stwa" value="00" /> 
    <input type="button" id="theButton" name="theButton" value="" /> 
</form>