JQuery学习笔记1:无效的p click 事件

学习Jquery第一天 ,让一个p tag 事件 click 里面 执行 显示一个对话框
错误的代码:
ContractedBlock.gif ExpandedBlockStart.gif 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">
<id="p123">
  Hello.
</p>


<p  >Hello</p>

</body>
</html

在浏览器里面调试始终不正确,后来发现,原来所有代码都要写在
< script  type ="text/javascript" >
  $(document).ready(
function (){
    
   
// 这里写代码
});
</ script >  

所以正确的代码是
ContractedBlock.gif ExpandedBlockStart.gif 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">
<id="p123">
  Hello.
</p>


<p  >Hello</p>

</body>
</html>



转载于:https://www.cnblogs.com/apple1/archive/2009/09/15/1566798.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值