2014-09-19 22 views
0

我在html頁面下面。使用Jquery/Javascript的Gwt原始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"> 

但注意輸出。輸入的結束標記丟失。我怎樣才能得到確切的原始內容的HTML沒有缺少結束標記input

我期待下面的輸出。

<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

輸入元素不需要結束標記。 http://www.w3schools.com/tags/tag_input.asp – ChaoticNadirs 2014-09-19 10:23:56

+0

感謝您的回答。仍然我需要一個結束標籤,如,因爲raw html是XML解析器的輸入。否則,XML解析器會抱怨輸入沒有結束標記。所以我需要它。 – user755806 2014-09-19 10:28:17

+0

任何解決方案? – user755806 2014-09-19 10:30:13

回答

0

試試這個:

$(document).ready(function(){ 
    $("button").click(function(){ 
    alert($("#aaa").html() +"</input>"); 
    }); 
}); 
+0

我試過..沒有變.. – user755806 2014-09-19 11:08:46

+0

我編輯了我的代碼。你出來。 – 2014-09-19 11:18:19