removeProp(name)

2018-02-24 15:14 更新

返回值:jQueryremoveProp(name)

概述

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

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

參數

propertyNameStringV1.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. 
以上內容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號