新手遇到onclick问题,求帮助!
我只想测试一下,为什么我点击的时候,不能触发弹窗“qq被点击了!”呢?谢谢!
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script>
var oDiv = document.getElementById("qq");
oDiv.onClick = function(){
alert("qq被点击了!");
}
</script>
</head>
<body>
<div id="qq" onclick="oDiv()" >test</div>
</body>
</html>
------解决方案--------------------<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script>
function oDiv(){
alert("qq!");
}
</script>
</head>
<body>
<div id="qq" onclick="oDiv()" >test</div>
</body>
</html>
这样试试
------解决方案--------------------放到onload里边, onclick是小写
window.onload = function(){
var oDiv = document.getElementById("qq");
oDiv.onlick = function(){
alert("qq被点击了!");
}
}