我用 Html 写了一个函数,效果很好。 但是我的老师说我们需要将代码从 HTML 文件中分离出来。所以我需要在 .js 文件中实现这段代码。谁能告诉我该怎么做?我想像这样在 JS 中创建一个函数,但它不起作用。
感谢您的帮助!
<script>
$(document).ready(function() {
$("#down").on('click',function(event) {
$('html,div-b').animate({scrollTop: document.body.scrollHeight
-1100},"slow");
});
});
最佳答案
你曾经像这样使用html文件
<html>
<body>
<script src="demo.js">
</script>
</body>
</html>
并像这样保留js文件 demo.js文件
function test(){
<!---your code here-->
}
关于javascript - 如何在 .js 文件中编写 JS 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46930297/