第二十节 jQuery操作属性

 1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset="UTF-8"> 5 <title>Document</title> 6 <script type="text/javascript" src="../jquery-1.12.4.min.js"></script> 7 <script type="text/javascript"> 8  $(function(){ 9 var $a = $(.link);10 11 // 读取class属性值,没有设置的属性读取为空,读取的图片地址为完整的绝对地址12  console.log($a.prop(class));13  console.log($a.prop(title));14 15 // 设置属性值16  $a.prop({href:http://www.baidu.com,title:百度网链接});17 18 // 读标签里的内容19  console.log($a.html());20 21 // 往标签内写内容22  console.log($a.html(这是再次写入的内容))23  });24 </script>25 </head>26 <body>27 <a href="#" class="link">这是一个链接</a>28 </body>29 </html>

 

相关文章