Javascript jquery,保存整个DOM以便重新加载 $(函数(){ var xml='bar'; 打开(“文本/xml”、“替换”); document.write(xml); document.execCommand('SaveAs',true,'file.xml'); });
这个html文件生成一个xml文件(在IE中)并创建一个“另存为”对话框。但是,我希望在保存文件后将文档重置为其以前的状态(在“替换”之前)。使用纯javascript或jQuery可以实现这一点吗?感谢您在Javascript jquery,保存整个DOM以便重新加载 $(函数(){ var xml='bar'; 打开(“文本/xml”、“替换”); document.write(xml); document.execCommand('SaveAs',true,'file.xml'); });,javascript,jquery,xml,dom,Javascript,Jquery,Xml,Dom,这个html文件生成一个xml文件(在IE中)并创建一个“另存为”对话框。但是,我希望在保存文件后将文档重置为其以前的状态(在“替换”之前)。使用纯javascript或jQuery可以实现这一点吗?感谢您在中对文档运行该代码,而不是替换当前文档。您不需要保存整个dom。只需保存可以更改的值(表单字段和其他小的用户界面位,用于交流)并在必要时进行更新 如有必要,编写一个重置函数,您可以在需要时调用它。简单地说不是,因为document.open()会清除文档。 你应该照SLaks说的做 阅读它或
中对文档运行该代码,而不是替换当前文档。您不需要保存整个dom。只需保存可以更改的值(表单字段和其他小的用户界面位,用于交流)并在必要时进行更新
如有必要,编写一个重置函数,您可以在需要时调用它。简单地说不是,因为document.open()会清除文档。
你应该照SLaks说的做
阅读它或者在弹出窗口中完成所有操作
$(函数(){
var popup=window.open()
var xml='bar'
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title></title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript">
$(function(){
var xml = '<?xml version="1.0"?><foo><bar>bar</bar></foo>';
document.open("text/xml", "replace");
document.write(xml);
document.execCommand('SaveAs',true,'file.xml');
});
</script>
</head>
<body>
</body>
</html>
我想我可能误解了这个问题。谢谢,下面的问题:有没有jquery版本的文档。open
?我想文档。write
可以替换为append()
。如果可能的话,我想设置xml的编码。否。文档。write
与append
无关。
popup.document.open("text/xml", "replace");
popup.document.write(xml);
popup.document.execCommand('SaveAs',true,'file.xml');
popup.close();
});