我尝试使用$("html").html(this.responseText);
. 它替换了内容,但不替换 head 和 body 标签。
因此,例如,如果我想替换此内容:
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<script>...</script>
<script>...</script>
</head>
<body>
<h1>This is a Heading</h1>
<script>...</script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
然后我在检查器中检查我的 HTML 结构,结果如下:
<!DOCTYPE html>
<html>
<title>Page Title</title>
<script>...</script>
<script>...</script>
<h1>This is a Heading</h1>
<script>...</script>
</html>
Run Code Online (Sandbox Code Playgroud)
它弄乱了我的 css。我试过没有脚本,它工作得很好。这个问题的解决方案是什么?
我也尝试过使用 javascript 方法
document.open();
document.write(this.responseText);
document.close();
Run Code Online (Sandbox Code Playgroud)
但它混淆了我的 javascripts。我收到重新声明语法错误。
我要实现的真实代码:
<script>
var frm = $('#frm');
var submitActors = frm.find('input[type=submit]');
var submitActor = null;
submitActors.click(function(event) {
submitActor = this;
});
frm.unbind('submit').submit(function () {
var formAction = document.getElementById("frm").getAttribute('action'); // …
Run Code Online (Sandbox Code Playgroud)