日期:2014-05-18  浏览次数:20471 次

js中怎么实现下载?
function openUrl(url) {
  if (document.all) {
  var a = document.createElement("A");
  a.target = "_blank";
  a.href = url;
  document.body.appendChild(a);
  a.click();
  setTimeout(function() { a.parentNode.removeChild(a); }, 50);
  }
  else window.open(url, "_blank");
  openUrl("");
}


 <span style=" cursor:pointer;" onclick="openUrl('文件名')">下载</span>
当我点的时怎么去下载我根目录下的文件呢,高手么多多指教下了

------解决方案--------------------
想必楼主是想隐藏下载地址? 但是这种办法根本不能隐藏 懂点HTML就知道怎么查到你的下载地址

不过还是给你写出来吧
<script>
function openUrl(fileName)
{
var weburl=window.location.href;
var url=weburl+"/"+fileName;
open(url, "_blank");
}
</script>
<span onclick="openUrl('文件名')">点击下载</span>

如果要隐藏下载路径 建议使用加密