如何在 html 中调用 js document.ready 函数
How to call js document.ready function in html?
我正在使用jquery document.ready编写一个网页游戏。当我在 html 中调用 js 函数时,它不起作用:
.js:
$(document).ready(function(){
function init(){blablabla...}
})
.html:
<script src="function.js"></script>
<script>
function bla(){
if (blablabla)
init();
}
</script>
我只学习了几个星期的html和js。我不知道为什么它不起作用。
请按照下面的步骤操作:
有两个版本的jQuery可供下载: 缩小和压缩
jQuery 库是一个单一的 JavaScript 文件,您可以使用 HTML <script>
标记引用它(请注意,<script>
标记应该在 <head>
部分中(:
喜欢:
<head>
<script src="jquery-1.12.0.min.js"></script>
</head>
您可能已经注意到,我们示例中的所有 jQuery 方法都位于文档就绪事件中:
<script>
$(document).ready(function(){
// jQuery methods go here...
});
</script>
实现预期结果的一种方法是将init
设置为document
的属性
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js">
</script>
<script>
$(document).ready([
function() {
function init() {
// do stuff
alert("blablabla...")
}
// set `init` as property of `document`
this.init = init;
},
function bla() {
if ($.isReady /* blablabla */)
document.init();
}
])
</script>
<body></body>
相关文章:
- document.getElementById在js中不起作用
- JS DOM - document.getElementById 和按名称选择之间的区别
- document.ready是在async js之后加载的
- 如何在One'中包含jQuery.js;s Own.js在$(document).ready之前
- 使用document.location=file_url.mp3触发从JS下载-不正确
- 在 meteor js 中为 window.onload(function(){}) 和 $(document).rea
- “document.write”在这个js片段中做了什么
- $(document).ready() 在 IE 中使用 require.js 优化代码
- 当 document.ready 中的函数完成时执行 js 函数
- 如何在 html 中调用 js document.ready 函数
- 我想在js文件中包含$(document).keydown(function (e) {,但我无法使其工作
- 如何调用 Document.ready 内部的外部.js,方法是从 HTML 传入变量来调用下面的.js文件
- JS:创建函数并在$(document).ready中声明的正确方法
- JS: difference between document.evaluate(".//html"
- 是否可以在JS中构建HTML,以使用document.write插入到没有HTML 的HTML中
- 将JS分解为带有$(document).ready()的文件,但保留范围
- document.ready在外部JS文件中,用于检测加载哪个文件
- JS: document.write (calling CSS)
- JS document.write函数并打印字符^
- Prototype.js & document.createElement()