我有一个Web应用程序,它通过appendChild()功能使用JavaScript添加HTML元素(如div)。当我使用Firebug检查(添加div之后)时,它显示了新添加的div。但是,当我在浏览器中看到源代码时,它并不能反映所做的更改。
我的问题是:如何使用JavaScript或jQuery将新添加的div以及其他HTML元素另存为HTML文件?
源代码:
<html>
<head>
<title>Page title</title>
<script src="https://code.jquery.com/jquery-2.2.3.min.js"></script>
<script>
$(document).ready(function() {
$('#btnAddtoList').click(function(){
if( $('#inputAddtoList').val() == '' ) {alert("please enter some value."); }
var text = $('#inputAddtoList').val();
var newDiv = $('<div class="listing"><h4>' + text + '</h4></div>');
$('body').append(newDiv);
$('#inputAddtoList').val('');
});
});
</script>
</head>
<body>
Enter Question: <BR/><textarea id="inputAddtoList" rows="5" cols="50" placeholder="Enter Question Here..." autofocus></textarea>
<button id="btnAddtoList">Add Question</button>
<BR /><BR />
<strong>Question :</strong>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)