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>

相关文章:

  • 2021-07-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-25
  • 2022-03-03
  • 2021-12-13
猜你喜欢
  • 2021-08-27
  • 2021-12-23
  • 2021-09-20
  • 2022-12-23
  • 2021-08-16
  • 2021-11-17
相关资源
相似解决方案