单击链接时,我希望用户下载一个文件(在 href 中)。同时,在同一个点击中,我想将它们向下滚动到一个表单。
根据我的代码,我只能做其中之一。我无法执行这两个操作。
HTML
<a href="http://www.cdc.gov/animalimportation/images/dog2.jpg" download="dog2.jpg"
class="scroll-to-bottom-link">Scroll to bottom</a>
<p>here is some secondary information</p>
jQuery
$('.scroll-to-bottom-link').click(function(){
$('html, body').animate({scrollTop : $('body').height() }, 800);
return false;
});
关于如何做到这一点有什么想法吗?我找到的其他选项使用 href="#"
,但我需要它来下载。
最佳答案
我会在 a
标签中放置一个 div
并将事件附加到它上
<a href="http://www.cdc.gov/animalimportation/images/dog2.jpg" download ><div class="scroll-to-bottom-link">Scroll to bottom</div></a>
<p>here is some secondary information</p>
然后从函数中删除 remove false
。
$('.scroll-to-bottom-link').click(function(){
$('html, body').animate({scrollTop : $('body').height() }, 800);
});
关于javascript - 下载文件并在单击链接时滚动到底部 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29260569/