JQuery如何从html内容的一部分中删除“id”

我想做这样的事情:

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()行,否则取消注释.

相关文章

页面搜索关键词突出 // 页面搜索关键词突出 $(function () {...
jQuery实时显示日期、时间 html: <span id=&quot...
jQuery 添加水印 <script src="../../../.....
中文:Sys.WebForms.PageRequestManagerParserErrorExceptio...
1. 用Response.Write方法 代码如下: Response.Write(&q...
Jquery实现按钮点击遮罩加载,处理完后恢复 思路: 1.点击按...