第1个回答 2016-06-15
用jQuery自带方法/函数来获取outerHTML属性是需要重写jquery的outerHTML方法。
两种实现方法:
1、直接扩展outerHTML:
jQuery.fn.outerHTML = function(s) {
return s
? this.before(s).remove()
: jQuery("<p>").append(this.eq(0).clone()).html();
};
2、包装成匿名函数:
(function($) {
$.fn.outerHTML = function() {
return $(this).clone().wrap('<div></div>').parent().html();
};
})(jQuery);