首頁  >  屬性  > removeProp(name)

返回值:jQuery removeProp(name)

概述

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

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

參數

propertyName String V1.6

要刪除的屬性名

示例

描述:

設定一個段落數字屬性,然後將其刪除。

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")), ". ");
結果:

The secret luggage code is: 1234. Now the secret luggage code is: undefined.