我有一堆复选框,链接到用户可以下载的文档。我在这里攻击了一些代码。基于复选框的文件下载
到目前为止,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