当用户单击“类似下载”时,我尝试下载文件。我发现此链接。它打开文件。不会自动开始下载文件。 Download File Using jQuery .\
$('a').click(function(e) {
e.preventDefault(); //stop the browser from following
window.location.href = 'http://code.jquery.com/mobile/1.4.2/jquery.mobile-1.4.2.min.css';
});
它应该自动开始下载。
最佳答案
不需要 jQuery,只需将“download”属性添加到您的 anchor 即可:
<a download href="http://code.jquery.com/mobile/1.4.2/jquery.mobile-1.4.2.min.css">
Download now!
</a>
关于javascript - 如何在 jQuery 中下载文件(已经使用 href 和 PreventDefault)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23878677/