我正在使用 jQuery Mobile 和 Phonegap 创建一个学习计时器,并尝试通过 JS 更改表单值。
表单值:
<form action="javascript:void(null);" id="theTimer" name="theTimer">
<input id="timerDisplay" type='text' name="theTime" readonly/>
<br />
<input type='submit' name="start" value="Start" onclick="Start()"/>
<input type='submit' name="stop" value="Stop" onclick="Stop()"/>
<input type='submit' name="pause" value="Pause" onclick="Pause()"/>
</form>
JS代码:
function Pause() {
if (timerID) {
clearTimeout(timerID);
}
if (myTimer) {
clearInterval(myTimer);
}
if (document.theTimer.pause.value == "Pause") {
document.theTimer.pause.value = "Resume";
} else {
document.theTimer.pause.value = "Pause";
tToday = new Date();
total_time = tToday.getTime() - tDiff;
tStart = new Date(total_time);
timerID = setTimeout(UpdateTimer, 1000);
startTimer();
}
}
问题是,当我使用另一个框架时,表单值 Pause 会更改为 Resume 并通过 Pause() 函数继续暂停...现在它根本看不到 Pause 表单值...
为了获得表单值“暂停”以更改为“恢复”,我缺少什么?
最佳答案
如果你使用jquery,你可以这样做: if ($('input[name=pause]').val() == "暂停") { $('input[name=pause]').val("继续"); }
而不是
if (document.theTimer.pause.value == "暂停") { document.theTimer.pause.value = "恢复"; }
关于javascript - JS 或 jQuery 更改表单对象的值时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6103418/