我想要做這樣的事去掉「標識」:JQuery的如何從HTML內容的一部分
var html = $("#media").html();
$("#multimedia-content").append(html);
$("#multimedia-content").filter("*").removeAttr("id");
這是第3行失敗,我想從這個部分HTML,但我不刪除所有的ID不知道如何做選擇。
謝謝!
我想要做這樣的事去掉「標識」:JQuery的如何從HTML內容的一部分
var html = $("#media").html();
$("#multimedia-content").append(html);
$("#multimedia-content").filter("*").removeAttr("id");
這是第3行失敗,我想從這個部分HTML,但我不刪除所有的ID不知道如何做選擇。
謝謝!
就個人而言,我會嘗試這樣的:
$('#media') // grab the media content
.clone() // make a duplicate of it
//.find('*') // find all elements within the clone
.removeAttr('id') // remove their ID attributes
//.end() // end the .find()
.appendTo('#multimedia-content'); // now add it to the media container
如果您想的#media失去其ID爲好,去除.find()
和.end()
線,否則取消註釋它們。
爲了從#multimedia-content
任何子元素中所有的id
屬性:
$("#multimedia-content").find().each(function() {
$(this).removeAttr("id");
});
你應該這樣做:
$("#multimedia-content *").removeAttr("id");
這將刪除內部#multimedia-content
它的作品我也喜歡它,謝謝。 – Santiago
嘗試元素的所有IDS這樣的:
$("*[id], #multimedia-content").removeAttr("id");
這樣,它只會從包含id屬性的元素id屬性。
爲什麼不在第一行調用'removeAttr',或者使用'$('#multimedia-content *')。removeAttr('id');'如果這是jQuery> = 1.6,使用['.rempveProp'](http://api.jquery.com/removeProp/)。 –