我在这里遇到麻烦。我有一个应该有两个状态的变量。我想检查状态是否已经改变,即使它已经改变了,我的功能还是继续说它没有。看看:
<script type="text/javascript">
var i = 0;
//More unrelated code here
function Talk(url) {
just_done = 0;
//alert("Hey!");
buttons = document.getElementsByTagName("input");
iframe = document.getElementsByTagName("iframe");
//alert("Hey!");
if (url == "scheduler.html" && talk == 0 && just_done == 0) {
trc = parseInt(getCookie("trc"));
if (getCookie("trc") == "NaN") {
trc = 0;
}
if ((getCookie("trc")) == undefined) {
trc = 0;
}
//alert("It started.");
stop = 0;
buttons[0].value=" Stop Listening ";
iframe[0].src=url;
//alert("It should be removed");
talk = 1;
just_done = 1;
}
if (url == "scheduler.html" && talk == 1 && just_done == 0) {
//alert("It stopped.");
stop = 1;
full_time = getTimeSince() + klove;
document.cookie="klove=" + full_time;
buttons[0].value=" Listen Now ";
iframe[0].src="";
// //alert("It should be removed");
talk = 0;
just_done = 1;
//alert(full_time);
}
if (url == "http://emf.mp3.miisolutions.net:80/kl/klove_itunes" && music == 0 && just_done == 0) {
klove = parseInt(getCookie("klove"));
if ((getCookie("klove")) == "NaN") {
klove = 0;
//alert("K-Love seemed to be null.");
}
if ((getCookie("klove")) == undefined) {
klove = 0;
}
//alert("It started.");
stop = 0;
iframe[0].src=url;
// //alert("It should be removed");
music = 1;
just_done = 1;
}
if (url == "http://emf.mp3.miisolutions.net:80/kl/klove_itunes" && music == 1 && just_done == 0) {
//alert("It stopped.");
stop = 1;
full_time = getTimeSince() + klove;
document.cookie="klove=" + full_time;
iframe[0].src="";
// //alert("It should be removed");
music = 0;
just_done = 1;
//alert(full_time);
}
if (url == "http://tunein.streamguys1.com/cnn" && news == 0 && just_done == 0) {
cnn = parseInt(getCookie("cnn"));
if ((getCookie("cnn")) == "NaN") {
cnn = 0;
//alert("CNN seemed to be null.");
}
if ((getCookie("cnn")) == undefined) {
cnn = 0;
}
//alert("It started.");
stop = 0;
iframe[0].src=url;
// //alert("It should be removed");
news = 1;
just_done = 1;
}
if (url == "http://tunein.streamguys1.com/cnn" && news == 1 && just_done == 0) {
//alert("It stopped.");
stop = 1;
full_time = getTimeSince() + cnn;
document.cookie="cnn=" + full_time;
iframe[0].src="";
// //alert("It should be removed");
news = 0;
just_done = 1;
//alert(full_time);
}
}
stop = 0;
Time();
function Time() {
if (stop == 0) {
i = i + 1;
alert(i);
setTimeout(Time, 1000);
}
if (stop != 0) {
alert("I'm done. It's " + i);
}
}
</script>
<input width="10px" height="6px" id="button" type="button" onClick='Talk("scheduler.html")' value=" Listen Now "></input>
奇怪我有这个问题,当他们遇到类似的问题时,我已经在这个网站上关注了每个人的说明,但这仍然无效。
编辑:让我补充一点,将stop设置为1的if语句在另一个函数中。
编辑2:这是更多代码,因此您可以触发我的问题。