----------------------------------------------知识点来自§ 薄樱 §……Design of paradise----------------------------------------
--------------------------------Link:http://www.cnblogs.com/CherryGhost/archive/2011/08/31/2160668.html----------------
jquery获取完整的html方法,兼容ie8,firefox
(function($) {
var oldHTML = $.fn.html;
$.fn.formhtml = function() {
if (arguments.length) return oldHTML.apply(this,arguments);
$("input,textarea,button", this).each(function() {
this.setAttribute('value',this.value);
});
$(":radio,:checkbox", this).each(function() {
if (this.checked) this.setAttribute('checked', 'checked');
else this.removeAttribute('checked');
});
$("option", this).each(function() {
if (this.selected) this.setAttribute('selected', 'selected');
else this.removeAttribute('selected');
});
return oldHTML.apply(this);
};
})(jQuery);
调用方法:$("#abc").formhtml();