ボタンクリックで関数を呼び出そうとしていますが、何らかの理由でボタンが関数を呼び出すことはありません。 Dreamweaverでは構文エラーは表示されません。誰も私のボタンが動作していない理由を教えてもらえますか?ボタンが関数を正しく呼び出せない
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
</head>
<head>
<title></title>
<script type="text/javascript">
var imgObj = 0;
var imgObj1 = 0;
var animate;
var animate1;
function init(){
imgObj = document.getElementById('red');
imgObj.style.position= 'relative';
imgObj.style.left = '0px';
imgObj1 = document.getElementById('blue');
imgObj1.style.position = 'relative';
imgObj1.style.left = '0px';
}
function moveRight(){
imgObj.style.left = parseInt(imgObj.style.left = 0) + Math.floor((Math.random() * 100) + 1) + 'px';
animate = setTimeout(moveRight(), 1000);
imgObj1.style.left = parseInt(imgObj1.style.left = 0) + Math.floor((Math.random() * 100) + 1) + 'px';
animate1 = setTimeout(moveRight(), 1000);
if (imgObj.style.left >= 1000px || imgObj1.style.left >= 1000px)
{
break;
else if
{
imgObj.style.left>= 1000
MessageBox.show("The Red Car has won the Race!");
}
else
{
MessageBox.show("The Blue Car has won the Race!");
}
}
}
</script>
</head>
<body onload = "init()">
<form>
<input type="button" value="Start" onclick="moveRight()" />
<br/><br/><br/><br><br/><br/><br/>
<img id="red" src="redcar.png" alt="Car 1"/>
<br/><br/><br/><br>
<img id="blue" src="bluecar.png" alt ="Car 2" />
</form>
</body>
</html>
何のボタンをクリックされるが何をしたとします
は、ここで「作業」バージョンですか? – gurvinder372
1つのこと; 'setTimeout(moveRight(1000));'は 'setTimeout(moveRight、1000);でなければなりません – Andy
ボタンのクリックは機能しますか?別名、アラートを追加してアラートを出しますか? imgObjが正しく見つかりましたか?次に、タイムアウトの構文です。 – Shilly