这是使用jQuery的一种方法:
var attrs = { };$.each($("b")[0].attributes, function(idx, attr) { attrs[attr.nodeName] = attr.nodevalue;});$("b").replaceWith(function () { return $("<h1 />", attrs).append($(this).contents());});更新 ,这是一个插件:
(function($) { $.fn.changeElementType = function(newType) { var attrs = {}; $.each(this[0].attributes, function(idx, attr) { attrs[attr.nodeName] = attr.nodevalue; }); this.replaceWith(function() { return $("<" + newType + "/>", attrs).append($(this).contents()); }); };})(jQuery);


