- <!DOCTYPE html>
- <HTML lang="en">
- <head>
- <meta charset="UTF-8">
- <title>
- Document
- </title>
- <script type="text/javascript" src="../jquery-1.12.4.min.js">
- </script>
- <script type="text/javascript">
- $(function() {
- var $a = $('.link');
- // 读取 class 属性值, 没有设置的属性读取为空, 读取的图片地址为完整的绝对地址
- console.log($a.prop('class'));
- console.log($a.prop('title'));
- // 设置属性值
- $a.prop({
- 'href': 'http://www.baidu.com',
- 'title': '百度网链接'
- });
- // 读标签里的内容
- console.log($a.HTML());
- // 往标签内写内容
- console.log($a.HTML('这是再次写入的内容'))
- });
- </script>
- </head>
- <body>
- <a href="#" class="link">
- 这是一个链接
- </a>
- </body>
- </HTML>
来源: http://www.bubuko.com/infodetail-3461684.html