我是新来的HTML,CSS和JavaScript,我偶然发现了一个问题。这段代码应该创建一个随着时间的推移向右移动的图片,但只有当我删除doctype代码行时才能使用。我在验证器中试过这段代码,它没有显示任何错误,但是它没有做我想做的事情,除非我删除了文档类型。我应该在这里改变什么?JavaScript不能与doctype html一起使用?
<!doctype html>
<html>
<head>
<title>Timer pomeranje</title>
<script>
var the_timer, x_position = 0, the_image;
function set_timer() {
the_image = document.getElementById("djuro_image");
x_position = x_position + 1;
the_image.style.left=x_position;
the_timer = setTimeout(set_timer, 50);
}
</script>
</head>
<body onload = "set_timer()">
<img src = "Djuro.png" id = "djuro_image" style = "position:absolute; left:0px" alt = "Djuro">
</body>
</html>
你不应该写你的JavaScript在你的脑袋 – gr3g
你”必须告诉你正在使用哪个浏览器。 – JJJ