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