Javascript Jquery下载结果文件
我需要创建一个按钮,点击时显示“加载”,然后弹出一个电子表格,其中包含用户创建的表格的结果。我把代码作为链接,而不是按钮。我怎样才能解决这个问题 这是用于创建表并从指定链接将结果显示在电子表格中的脚本:Javascript Jquery下载结果文件,javascript,jquery,html,datatables,Javascript,Jquery,Html,Datatables,我需要创建一个按钮,点击时显示“加载”,然后弹出一个电子表格,其中包含用户创建的表格的结果。我把代码作为链接,而不是按钮。我怎样才能解决这个问题 这是用于创建表并从指定链接将结果显示在电子表格中的脚本: makeTable = function(query) { var q = encodeURIComponent(query); $('#example').dataTable({ "oLanguage": {"sSearch": "Filter results:
makeTable = function(query) {
var q = encodeURIComponent(query);
$('#example').dataTable({
"oLanguage": {"sSearch": "Filter results:"},
"bProcessing": true,
"bDestroy":true,
"sAjaxSource": $.sprintf('http://...?q=%s',q),
"aoColumns":[
{"mData":"id", "sWidth": "20px", "sTitle":"ID"},
{"mData":"chamber", "sWidth": "10px", "sTitle":"Chamber"},
{"mData":"date", "sWidth": "85px", "sTitle":"Date"},
{"mData":"yea","sTitle":"Vote","sWidth":"80px"},
{"mData":"descriptionShort", "sWidth": "200px","sTitle":"Description"}
],
"fnRowCallback": function( nRow, aData, iDisplayIndex ) {
$('td:eq(0)', nRow).html($.sprintf('<a onclick="setviz(\'%s\');setview(\'visualize\')">%s</a>',aData['id'],aData['id'])).attr("title", "Click to explore this vote");
$('td:eq(3)', nRow).html($.sprintf('%s-%s', aData['yea'], aData['no']));
$('td:eq(4)', nRow).attr("title",aData['description']);
resultids.push(aData['id']); // build vector vote ids (nothing to do with the table)
return nRow;
},
"fnInitComplete": function(oSettings, json) {
$('#downloadExcel').attr('href','http://...?ids=' + resultids.join()); // Make download link
}
});
}
makeTable=函数(查询){
var q=组件(查询);
$('#示例')。数据表({
“oLanguage”:{“sSearch”:“筛选结果:”},
“bProcessing”:正确,
是的,
“sAjaxSource”:$.sprintf('http://...?q=%s",q),,
“aoColumns”:[
{“mData”:“id”,“sWidth”:“20px”,“sTitle”:“id”},
{“mData”:“chamber”,“sWidth”:“10px”,“sTitle”:“chamber”},
{“mData”:“date”,“sWidth”:“85px”,“sTitle”:“date”},
{“mData”:“yes”,“sTitle”:“Vote”,“sWidth”:“80px”},
{“mData”:“descriptionShort”,“sWidth”:“200px”,“sTitle”:“Description”}
],
“fnRowCallback”:函数(nRow、aData、iDisplayIndex){
$('td:eq(0'),nRow).html($.sprintf('
下载
链接完全符合我的预期,但按钮没有
帮助?试试这个
<button id="downloadExcel">Download</button>
将url设置到窗口。location
将触发文件下载。您也可以尝试窗口。location.href
为什么不使用:?之前没有看到您的a->role=“button”结构=)role=“button”是屏幕阅读器的进一步信息,并描述了导致响应/操作的元素,按钮通常都会这样做。我相信提供的HTML代码是使用链接的工作代码。请验证/篡改此代码和/或提供不按预期工作的代码。
<button id="downloadExcel">Download</button>
"fnInitComplete": function(oSettings, json) {
$('#downloadExcel').click(function(){
window.location = 'http://...?ids=' + resultids.join();
})
}