我有一堆複選框,鏈接到用戶可以下載的文檔。我在這裏攻擊了一些代碼。基於複選框的文件下載
到目前爲止,downloadChecked函數按預期工作,但我似乎無法使makFrame函數正常運行。目前它似乎沒有做任何事情。
function makeFrame(url)
{
ifrm = document.createElement("IFRAME");
ifrm.setAttribute("style", "display:none;") ;
ifrm.setAttribute("src", url) ;
ifrm.style.width = 0+"px";
ifrm.style.height = 0+"px";
document.body.appendChild(ifrm) ;
}
function downloadChecked()
{
for(i = 0 ; i < document.downloadform.elements.length ; i++)
{
foo = document.downloadform.elements[ i ] ;
if(foo.type == "checkbox" && foo.checked == true)
{
makeFrame('somefile.do?command=download&fileid=' + foo.name);
}
}
}
和相應的HTML
<form name="downloadform">
<input type="checkbox" name="file" id="file1"
value="file source etc" />
<input type="checkbox" name="file" id="file2"
value="file source etc" />
<input type="button" value="Download all" onClick="downloadChecked();" />
檢查開發人員/調試工具是否有任何錯誤。這將幫助我們確定你的功能在哪一點失敗。如果您使用Firefox,則需要使用[Firebug](http://getfirebug.com/)。所有最近的市長瀏覽器,包括IE9 +都內置了開發者工具。 – Kiruse 2012-01-29 23:12:47
你的下載處理程序「somefile.do」是否爲你的文件設置了適當的頭文件? – Michal 2012-01-30 00:01:47