【发布时间】:2015-11-20 00:11:34
【问题描述】:
您好,我正在创建一个动态 html 部分,我有两个按钮:preview 和 download。
预览版运行良好。至于第二个按钮,即download,我想让按钮的动作使得如果单击download按钮,它会触发下载所有存储的html代码在变量rohit 中使用.html 格式。
我该怎么做?请告诉我。我在谷歌上搜索过,但找不到方法。
$(document).ready(function(){
var rohit = "<h2>Hello i m Dynamic Heading </h2>";
$('.preview').on('click', function(){
var myWindow = window.open('', "rohit", "width=800, height=400", '_blank');
myWindow.document.write(rohit);
});
$('.download').on('click', function(){
alert(rohit);
// here download code with html format how to do this .
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<button class="preview">click to preview</button>
<button class="download">CLick to Download</button>
和 Jsfiddle Link here
【问题讨论】:
-
html文件是否保存在你的服务器中?
-
没有保存到本地
-
谢谢先生。 @Raghavendra 我的问题是解决这个 url 你在聊天中 ping 我谢谢这个..
标签: javascript jquery html