jQuery attr(name)方法获取元素的属性
获取元素属性的语法格式如下:attr(name),其中name 表示属性的名称。
示例如下:
- <head>
- <title>获取元素的属性</title>
- <script type="text/javascript"
- src="../Jscript/jquery-1.4.2.js">
- </script>
- <script type="text/javascript"
- src="../Jscript/jquery-1.4.2-vsdoc.js">
- </script>
- <style type="text/css">
- body{font-size:12px}
- div{float:left;padding-left:10px}
- img{border:solid 1px #ccc;padding:3px;float:left}
- </style>
- <script type="text/javascript">
- $(function() {
- var strAlt = $("img").attr("src"); //属性值一
- strAlt += "<br/><br/>" + $("img").attr("title"); //属性值二
- $("#divAlt").html(strAlt);
- })
- </script>
- </head>
- <body>
- <img alt="" title="这是一幅风景画"
- src="../Images/img01.jpg" />
- <div id="divAlt"></div>
- </body>
- </html>
相关推荐
IT之家 2020-03-11
graseed 2020-10-28
zbkyumlei 2020-10-12
SXIAOYI 2020-09-16
jinhao 2020-09-07
impress 2020-08-26
liuqipao 2020-07-07
淡风wisdon大大 2020-06-06
yoohsummer 2020-06-01
chenjia00 2020-05-29
baike 2020-05-19
扭来不叫牛奶 2020-05-08
hxmilyy 2020-05-11
黎豆子 2020-05-07
xiongweiwei00 2020-04-29
Cypress 2020-04-25
冰蝶 2020-04-20