热门关键字:
jquery > jquery教程 > jquery教程 > 如何从jQuery中的HTML元素中删除属性

如何从jQuery中的HTML元素中删除属性

275
作者:管理员
发布时间:2021/2/4 14:04:33
评论数:0
转载请自觉注明原文:http://www.jq-school.com/Show.aspx?id=3829
答:使用jQueryremoveAttr()方法
您可以使用jQueryremoveAttr()方法从HTML元素中删除属性。


在下面的示例中,当您单击“删除链接”按钮时,它将href从链接中删除属性。让我们尝试一下,看看这种方法是如何工作的:


例试试这个代码»
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery Removing Attribute from HTML Element</title>
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script>
    $(document).ready(function() {
        $(".remove-attr").click(function(){            
            $("a").removeAttr("href");
        });
    });
</script> 
</head>
<body>
    <button type="button" class="remove-attr">Remove Link</button>
    <a href="#">Demo Link</a>
</body>
</html>





如果您觉得本文的内容对您的学习有所帮助:支付鼓励



关键字:jQuery
友荐云推荐