一起工作我有这个简单的代码,我只是无法让它工作。javascript onclick不能与`p.click =`
<html>
<head>
<script type="text/javascript">
window.onload = function() {
p = document.getElementById("foo");
p.click = function() { alert(p); };
}
</script>
</head>
<body>
<div id="foo" style="position:relative;width:100px;height:100px;background-color:red;"> </div>
</body>
</html>
Javascript is turned on。Javascript is turned on。如果我把()函数后,我可以让它自动运行。但是,onclick仍然无法工作。 Firebug没有显示任何错误。
是的,它应该是用户var p = document.getElementById(“foo”);虽然它正在工作。 http://stackoverflow.com/questions/1470488/difference-between-using-var-and-not-using-var-in-javascript – 2012-02-13 02:32:09