<!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=gb2312" />
<title>无标题文档</title>
</head>
<script language="javascript" src="jquery-1.3.2.js"></script><script language="javascript">
$("#run").click(function(){
alert("abc");
});
</script>
<body>
<button id="run">Run</button><div></div>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<script language="javascript" src="jquery-1.3.2.js"></script><script language="javascript">
$("#run").click(function(){
alert("abc");
});
</script>
<body>
<button id="run">Run</button><div></div>
</body>
</html>
<body>
<button id="run">Run </button> <div> </div>
<script>
$("#run").click(function(){
alert("abc");
});
</script>
</body>
$("#run").click(function(){
alert("abc");
});
});
<!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=gb2312" />
<title>无标题文档 </title>
</head>
<script language="javascript" src="jquery-1.3.2.js"> </script> <script language="javascript">
$(document).ready(function() {
$("#run").click(function() {
alert("Hello,world.");
});
})
</script>
<body>
<button id="run">Run </button> <div> </div>
</body>
</html>
原理: 调用DOM元素时 要保证该元素加载后才能调用。
用IE8或者ff firebug調試js
报一个找不到对象的错误,只不过jquery进行了封装,找不到对象不报错,但是测有反应。