温馨提示  2024年 6月我们已经停止开发者板块文章内容更新,谢谢来访。存档数据
知识 2023-08-26 34 次阅读

html中怎么去掉属性值

   

html中去掉属性值的方法 1. 使用attr()方法设置指定属性值为空字符串,语法“$(元素).attr(属性名,)”; 2. 使用removeattr()方法移除指定的属性,语法“$(元素).removeattr(属性名)”。

本教程操作环境windows7系统、jquery1.10.2&&html5版、dell g3电脑。

html中去掉属性值

1. 使用attr()方法设置指定属性值为空字符串

<!doctype html><html><head><script type=text/javascript src=js/jquery-1.10.2.min.js></script><script type=text/javascript>$(document).ready(function(){ $(button).click(function(){ $(img).attr(width,); });});</script></head><body><img src=img/2.jpg width=500/><br /><button>去除width属性值</button></body></html>

2. 使用removeattr()方法移除指定的属性

<!doctype html><html><head><script type=text/javascript src=js/jquery-1.10.2.min.js></script><script type=text/javascript>$(document).ready(function(){ $(button).click(function(){ $(img).removeattr(width); });});</script></head><body><img src=img/2.jpg width=500/><br /><button>去除width属性</button></body></html>

推荐教程html视频教程、jquery教程(视频)