首頁  >  屬性  > removeProp(name)

返回值:jQueryremoveProp(name)

jQuery removeProp() 方法概述

用來刪除由.prop()方法設置的屬性集

隨著一些內(nèi)置屬性的DOM元素或window對象,如果試圖將刪除該屬性,瀏覽器可能會產(chǎn)生錯誤。jQuery第一次分配undefined值的屬性,而忽略了瀏覽器生成的任何錯誤

參數(shù)

propertyNameStringV1.6

要刪除的屬性名

示例

描述:

設置一個段落數(shù)字屬性,然后將其刪除。

HTML 代碼:
<p> </p>
jQuery 代碼:
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")), ". ");
結(jié)果:
The secret luggage code is: 1234. Now the secret luggage code is: undefined.