问题来了 我有一个名为 javascript.js 的 javascript 文件,如下所示
$(document).ready(function(){
function init()
{
//code goes here
}
}
现在 index.html 文件有一个命令按钮,它应该调用 init() 函数。
<html>
<head><script src=javascript.js ....></script>
<body><button type="button" onclick="init()">Call Init!</button></body>
</html>
但它不会调用它。没有按预期发生任何事情。请提出解决方案。
最佳答案
您应该在 $(document).ready()
范围之外定义您的函数。
关于javascript - 从 html 调用 javascript 函数不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11814213/