Я пытаюсь вызвать функцию нажатием кнопки, но по какой-то причине кнопка не будет вызывать функцию. 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
Одна вещь; 'setTimeout (moveRight(), 1000);' должно быть 'setTimeout (moveRight, 1000);' – Andy
Нажимает ли кнопка кнопку? Ака, добавляет ли предупреждение предупреждение? Правильно ли imgObj? И тогда да, синтаксис тайм-аута. – Shilly