学习Jquery第一天 ,让一个p tag 事件 click 里面 执行 显示一个对话框
错误的代码:
code
<!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>jquery learn 1 </title>
<script src="./jquery/js/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$("#p123").click( function() { alert('Hello,world!'); } ); //显示对话框
</script>
</head>
<body id="defaultuser">
<p id="p123">
Hello.
</p>
<p >Hello</p>
</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>jquery learn 1 </title>
<script src="./jquery/js/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$("#p123").click( function() { alert('Hello,world!'); } ); //显示对话框
</script>
</head>
<body id="defaultuser">
<p id="p123">
Hello.
</p>
<p >Hello</p>
</body>
</html
在浏览器里面调试始终不正确,后来发现,原来所有代码都要写在
<
script
type
="text/javascript"
>
$(document).ready( function (){
// 这里写代码
});
</ script >
$(document).ready( function (){
// 这里写代码
});
</ script >
所以正确的代码是
Code
<!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>jquery learn 1 </title>
<script src="./jquery/js/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#p123").click( function() { alert('Hello,world!'); } );
});
</script>
</head>
<body id="defaultuser">
<p id="p123">
Hello.
</p>
<p >Hello</p>
</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>jquery learn 1 </title>
<script src="./jquery/js/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#p123").click( function() { alert('Hello,world!'); } );
});
</script>
</head>
<body id="defaultuser">
<p id="p123">
Hello.
</p>
<p >Hello</p>
</body>
</html>