html中怎么去掉属性值

html中怎么去掉属性值,第1张

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教程(视频)

以上就是html中怎么去掉属性值的详细内容,

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/698336.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-22
下一篇 2022-04-22

发表评论

登录后才能评论

评论列表(0条)

保存