<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>JQuery插件第二十三个:仿照DOM对象的outerHTML</title>
<script type="text/javascript" src="../jquery-1.6.js"></script>
<script type="text/javascript">
(function ($) {
$.fn.outerHTML = function(){
var str="";
var id="outerHTML"+new Date().getTime();
var outer=$("#"+id);
this.each(function(){
var obj=$(this);
if(outer.length==0)
outer= $("<div id="+id+" style='display:none' ></div>").appendTo('body');
obj.clone().appendTo("#"+id);
str+=outer.html();
outer.html('');
});
outer.remove();
return str;
};
})(jQuery);
$(document).ready(function () {
alert($("#sheng").outerHTML());
});
</script>
</head>
<body>
<div id="t">
<div>
<input type="button" id="btn" value="111" />
<input type="button" id="Button1" value="133" />
<div id="sheng" >有一种幸福,隽永平淡</div>
</div>
</div>
</body>
</html>