jQuery中 attr() 方法使用小结
2015-05-03 10:22
645 查看
定义和用法
attr() 方法设置或返回被选元素的属性值。
根据该方法不同的参数,其工作方式也有所差异。
实例1
设置被选元素的属性和值。
<html> <head> <script type="text/javascript" src="/jquery/jquery.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("button").click(function(){ $("img").attr("width","180"); }); }); </script> </head> <body> <img src="/i/eg_smile.gif" /> <br /> <button>设置图像的 width 属性</button> </body> </html>
实例2
返回被选元素的属性值。
<html> <head> <script type="text/javascript" src="/jquery/jquery.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("button").click(function(){ alert("Image width " + $("img").attr("width")); }); }); </script> </head> <body> <img src="/i/eg_smile.gif" width="128" height="128" /> <br /> <button>返回图像的宽度</button> </body> </html>
以上所述就是本文的全部内容了,希望大家能够喜欢。
您可能感兴趣的文章:
相关文章推荐
- jQuery中 attr() 方法使用小结
- jQuery操纵DOM元素属性 attr()和removeAtrr()方法使用详解
- jQuery操纵DOM元素属性 attr()和removeAtrr()方法使用详解
- jQuery操纵DOM元素属性 attr()和removeAtrr()方法使用详解
- jQuery使用attr()方法同时设置多个属性值用法实例
- JQuery .attr()和.prop()的正确使用场合,JQuery获取checkbox状态的正确方法
- jQuery使用scrollTop获取div标签的滚动条已滚动高度(jQuery版本1.6+时,用prop()方法代替attr()方法)
- jquery $(this).attr $(this).val方法使用介绍
- jquery $(this).attr $(this).val方法使用介绍
- jquery $(this).attr $(this).val方法使用介绍
- jquery $(this).attr $(this).val方法使用介绍
- jquery中get,post和ajax方法的使用小结
- jquery中get,post和ajax方法的使用小结
- Jquery中attr()方法的使用
- jquery 使用attr方法对checkBox进行全选和反选操作
- 使用jQuery的attr方法来修改onclick值
- 使用jQuery的attr方法来修改onclick值
- jquery中attr()方法的使用
- jQuery中prop()方法和attr()方法可能遇到的问题小结
- JQUERY中,复选框使用prop,attr方法时的一些注意