TestCode

博客园 首页 新随笔 联系 订阅 管理
1 <html xmlns="http://www.w3.org/1999/xhtml" >
2  <head>
3 <title>JQuery</title>
4 <script src="../js/jquery-1.4.2.js" type="text/javascript"></script>
5 <script type="text/javascript">
6 $(function(){
7 //动态创建元素使用选择器的易错点
8 var a = $("<a href='http://baidu.com' id='a1'>百度<a/>");
9 // $("#a1").text("谷歌"); //必须把动态创建的元素添加到页面上才能用选择器选择它,
10 $("body").append(a);
11 $("#a1").text("谷歌"); //必须把动态创建的元素添加到页面上才能用选择器选择它,这时对元素的修改才有效
12 })
13 </script>
14 </head>
15 <body>
16 </body>
17 </html>
posted on 2011-06-25 23:34  yaoguipeng  阅读(517)  评论(0编辑  收藏  举报