我想做一個提交按鈕,當它被點擊,然後圖像將移動,另一個按鈕,當它被點擊圖像將重置。onclick函數工作,但onsmit不
不知何故,如果我用onclick
函數做到這一點,圖像會移動,事情是好的,但如果我用它與onsubmit
函數,那麼它將無法正常工作。任何人都可以告訴我爲什麼?
這是我有我的腳本:
function catMoveRight()
{
document.getElementById("cat").style.left=parseInt(document.getElementById("cat").style.left)+1+"px";
}
window.onload=function()
{
catTimer = null;
document.getElementById("start").onsubmit=function()
{
if(catTimer == null)
{
catTimer = setInterval("catMoveRight()",1000);
}
}
}
這是我的HTML body
:
<img src="cat.jpg" id="cat" style=" position: absolute; left: 10px;"/><br/>
<form action=" " method="post" id="start">
<input type="submit" value="Start" style="position: absolute; left: 10px; top: 220px;" />
</form>
你需要證明你的代碼,'onsubmit'而不是爲'onclick',你可能會綁定事件的圖像,而不是形式,或者你可能會丟失一些其他錯誤。 –
'onsubmit'只有在你把它放到'
是否將'onsubmit'添加到表單中? – phenomnomnominal