jquery – 替换元素并保留属性

以下几乎可以用lis替换span [data-type =“yesno”]的所有实例,但我还想保留属性,类等.是否有办法以相同的方式继承属性作为 HTML
$('span[data-type="yesno"]').replaceWith(function(){
    return $("<li>",{html: $(this).html()});
})

解决方法

你必须循环你的元素属性
$('span[data-type="yesno"]').replaceWith(function(){
   $li = $("<li>",{html: $(this).html()});
   $.each(this.attributes,function(i,attribute){
        $li.attr(attribute.name,attribute.value);
  });
  return $li;
})

相关文章

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