我在html页面下面。
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
alert($("#aaa").html());
});
});
</script>
</head>
<body id="aaa">
<button>hello</button>
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
<input type="text" name="textt"/>
</body>
</html>
现在点击hello
按钮,我需要获取原始html内容。
它给出了以下输出。
<button>Change content of all p elements</button>
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
<input name="textt" type="text">
但请注意输出。输入的结束标记丢失。如何在不遗漏input
的结束标记的情况下获取html的确切原始内容?
我期待低于输出。
<button>Change content of all p elements</button>
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
<input name="textt" type="text"/>
谢谢!
答案 0 :(得分:0)
试试这个:
$(document).ready(function(){
$("button").click(function(){
alert($("#aaa").html() +"</input>");
});
});