導航:首頁 > 編程語言 > js刪除某屬性

js刪除某屬性

發布時間:2023-04-13 09:44:12

『壹』 js用正則表達式刪除指定屬性

varsource='<divstyle="a:a;b:b;c:c;"width="10%"height="dd"></div>';

//刪除width屬性及值。
console.log(source.replace(/width=".*?"/,''));

//刪除style屬性中的鍵值對b和c
console.log(source.replace(/(style=")(.*?)(")/,function(m,g1,g2,g3){

returng1+g2.replace(/s?(.*?):(.*?);/g,function(m,g1,g2){

//刪除b屬性和c屬性要改成其他屬性可版以在這里控制權
if(/^(b|c)$/.test(g1))
return'';

returnm;

})+g3;

}));

『貳』 如何用js刪除 dom元素的嵌入樣式(style)的一個屬性

將style中你想刪掉的屬性設為null應該是可以解決的,Chrome通過
例如:
elem.style["height"] = null;//徹底刪除elem的style屬性的height值

『叄』 js清除object

刪除對象,直接使用delete就可以了。
比如:delete document.getElementById('div');
刪除一個屬性的過程也很簡單,就是將其置為undefined:
user.name=undefined;
user.alert=undefined;
這樣就刪除了name屬性和alert方法。在之後的代碼中,這些屬性變的不可用。
在添加、修改或者刪除屬性時,和引用屬性相同,也可以採用方括弧([])語法:
user[「name」]=」tom」;
使用這種方式還有一個額外的特點,就是可以使用非標識符字元串作為屬性名稱,例如
標識符中不允許以數字開頭或者出現空格,但在方括弧([])語法中卻可以使用:
user[「my name」]=」tom」;
需要注意,在使用這種非標識符作為名稱的屬性時,仍然要用方括弧語法來引用:
alert(user[「my name」]);
而不能寫為:
alert(user.my name);

『肆』 在IE中,如何使用JS刪除DOM對象的屬性

in判斷的是對象的所有屬性,包括對象實例及其原型的屬性;

而hasOwnProperty則是判斷對象實例的是否具有某個屬性。

示例代碼:
<script type="text/javascript"> function Person(){ } Person.prototype.name = "allen"; var person = new Person(); console.log(person.hasOwnProperty("name")); //false console.log("name" in person); //true console.log(person.name); //"allen" person.name = "justforse"; console.log(person.hasOwnProperty("name")); //true console.log("name" in person); //true console.log(person.name); //"justforuse" delete person.name; console.log(person.hasOwnProperty("name")); //false console.log("name" in person); //true console.log(person.name); //"allen" </script>
以上代碼執行的時候,name屬性要麼是從實例中獲取的,要麼是來源於原型,所以使用in 來訪問 name屬性始終返回true;而hasOwnProperty()只在屬性存在與對象實例中時才返回true,當刪除了實例中的name屬性後,就恢復了原型中name屬性的連接,所以返回allen。

『伍』 如何用JS刪除響應頭裡面自定義的屬性

<div class="div-info" testAttr="myAttr" testAttr2="haha">

</div>

1、js中設置自定義屬性。

例如:$(".div-info").attr("testAttr3","houhou");

結果:給div設置了新的自定義屬性testAttr3,值為houhou

<div class="div-info" testAttr="myAttr" testAttr2="haha" testAttr3="houhou">

</div>

2、js中獲取自定義屬性值。

例如:$(".div-info").attr("testAttr");

結果:取到testAttr的值為:myAttr

3、js中修改自定義屬性值。

例如:$(".div-info").attr("testAttr","newAttr");

結果:將testAttr的值修改為newAttr

<div class="div-info" testAttr="newAttr" testAttr2="haha">

</div>

4、js中刪除自定義屬性
來自參考!

『陸』 js移除onmousemove屬性

var div = doucment.getElementById('xxx'); //先取得這個DOM
delete div.onmousemove;

不過說實話,一般都是回通過div.onmousermove = null 來進行事件答解除的

『柒』 如何利用JS實現在li中添加或刪除class屬性

可以使用jQuery的attr方法來實現對某一元素的的class的屬性的添加或者刪除,attr() 方法設置或返版回被選元素的屬性值.根據該方法不權同的參數,其工作方式也有所差異,可以使用removeclass來刪除class屬性。

工具原料:編輯器、瀏覽器

1、為li添加class屬性:

為某個li元素添加class=「special」的屬性

$('li').attr('class','special');

2、刪除class屬性:

$("li").removeClass("special");
});
閱讀全文

與js刪除某屬性相關的資料

熱點內容
字體在那個文件夾 瀏覽:342
蘋果4真機體驗 瀏覽:551
世界盃買在哪個app 瀏覽:631
魔力寶貝37版本 瀏覽:115
迷你編程的兌換碼是什麼 瀏覽:359
換一個文件櫃玻璃大概多少錢 瀏覽:971
什麼是代理網路 瀏覽:805
axure怎麼發布到手機app 瀏覽:227
如何做動漫視頻教程 瀏覽:331
蘋果公司企業架構 瀏覽:152
順豐錄音文件管理在哪裡 瀏覽:521
象山新建網站製作有哪些步驟 瀏覽:686
什麼app可以查化妝品的日期 瀏覽:174
中國移動香港的網路制式 瀏覽:752
編程在五行中屬什麼 瀏覽:54
中青校園app可以發什麼文章 瀏覽:397
主文件組可以存放哪些類型的文件 瀏覽:678
有沒有id和賬號和密碼 瀏覽:5
形勢和政策用什麼app 瀏覽:340
統贏編程nc文件輸出路徑設定 瀏覽:849

友情鏈接