.removeProp()
.removeProp( propertyName, value ) 返回: jQuery
描述: 為匹配的元素刪除設(shè)置的屬性。
-
version added: 1.6.removeProp( propertyName, value )
propertyName要設(shè)置屬性的名稱.
value要設(shè)置屬性的值
.removeProp()方法用來刪除由.prop()方法設(shè)置的屬性集。
隨著一些內(nèi)置屬性的DOM元素或window對象,如果試圖將刪除該屬性,瀏覽器可能會產(chǎn)生錯誤。jQuery第一次分配undefined值的屬性,而忽略了瀏覽器生成的任何錯誤。
其他注意事項:
- 在Internet Explorer之前的版本9,使用
.prop()設(shè)置DOM元素的屬性值以外的任何一個簡單的原始(數(shù)字,字符串或布爾)如果DOM元素之前從文檔中不刪除該屬性(使用.removeProp()),可能導(dǎo)致內(nèi)存泄漏。為了安全地設(shè)置對象無泄漏內(nèi)存值對DOM,使用.data()
Example:
設(shè)置一個段落數(shù)字屬性,然后將其刪除。
<!DOCTYPE html>
<html>
<head>
<style>
img { padding:10px; }
div { color:red; font-size:24px; }
</style>
<script src="http://code.jquery.com/jquery-git.js"></script>
</head>
<body>
<p></p>
<script>
var $para = $("p");
$para.prop("luggageCode", 1234);
$para.append("The secret luggage code is: ", String($para.prop("luggageCode")), ". ");
$para.removeProp("luggageCode");
$para.append("Now the secret luggage code is: ", String($para.prop("luggageCode")), ". ");
</script>
</body>
</html>