HTML代码:JQuery的上更改事件下载文件
<span>Download Report as</span>
<select id="comboFile">
<option value="none">Select</option>
<option value="http://somewhere/123.pdf">PDF</option>
<option value="http://somewhere/123.csv">CSV</option>
</select>
JQuery的:
$(document).ready(function() {
$("#comboFile").change(function() {
if ($(this).val() != "none") GetFile($(this).val());
$(this).val("none");
});
});
function GetFile(fileURL){
///Code to be filled
//window.location.href = fileURL;///Does not seem to work for new window
}
我非常卡住..我如何启动文件下载。我需要填写的代码为获取文件的功能...
你的代码工作给出。设置'window.location'应该可以工作:http://jsfiddle.net/XeAzy/。请注意,设置'window.location'后写入的JavaScript将不会运行。 – 2011-04-21 00:36:58
定义“似乎不起作用”。 – 2011-04-21 00:39:09
对不起,我本来应该在一扇窗户里说。它应该是'window.location.href = fileURL' – 2011-04-21 00:41:04