removeAttr() 方法从被选元素移除一个或多个属性。


<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>菜鸟教程(runoob.com)</title>
<script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js">
</script>
<script>
$(document).ready(function(){
    $("button").click(function(){
        $("p").removeAttr("id class");
    });
});
</script>
<style type="text/css">
#p1{
    color:white;
    background-color:green;
    font-size:20px;
    padding:5px; 
}
.blue{
    color:white;
    background-color:blue;
    font-size:20px;
    padding:5px; 
}
</style>
</head>
<body>

<h1>这是一个标题</h1>
<p id="p1">这是一个段落。</p>
<p class="blue">这是另一个段落。</p>
<button>移除所有P元素的id和类属性</button>

</body>
</html>

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM