我正在處理一個簡單的項目,該項目需要使用某些邏輯修改html源代碼,然後將修改後的html源代碼顯示一個按鈕被點擊時的div。使用Javascript或jQuery更改html源代碼,然後將更改後的源代碼顯示在文本區域中
我基本上想要做內兒童修改任何可能是子節點的深度。這裏發生的變化是在一個層面完成的,即跨度和h1標籤被消除。
顯示HTML按鈕顯示外部HTML文件的內容,而不是PAGE電泳代碼的源代碼轉換爲外部HTML文件的源代碼是這樣
<script>
function convertHtml() {
$body = $("#demo").text();
$fakediv = $("<div></div>");
$fakediv.html($body);
$fakediv.children().each(function(){
$thisText = $(this).text();
if($thisText)
$(this).text("@"+$thisText+"@")
});
$("#demo").text($fakediv.prop("outerHTML")); //fill in the div with converted html string
}
//Document is ready to execute the JS
$(document).ready(function() {
$("#convert").click(function(){
// alert($("#demo").text());
convertHtml();
});
});
</script>
請幫助。
謝謝!
分享你的代碼,我們將幫助您 – Zl3n
你看着'的jQuery()。文本()'? ''(「*」)。each(function(){$(this).text(「@」+ $(this).text()+「@」)});'示例不會產生確切的效果嵌套元素。 –
是的,我做到了,但那隻會修改DOM元素的內容,但我想修改的源代碼,我在我的帖子中提到的東西。 –