我在哪里放$(文件).ready()? [英] Where do I put the $(document).ready()?

查看:63
本文介绍了我在哪里放$(文件).ready()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试将JavaScript添加到我的HTML / CSS中,但一直在圈子里运行。

I've been trying to add JavaScript to my HTML/CSS, but been running around in circles.

我当前的设置是html,CSS的地方和JavaScript文件(2个文件;我的JavaScript代码和jQuery代码)都是独立的,但是通过html页面相互链接。

My current set-up is where the html, CSS, and JavaScript files (2 files; my JavaScript code, and jQuery's code) are all separate, but linked to each other via the html page.

所以这是我的问题:

1)我是否将链接放到html中的jQuery代码中头?或者在我的JavaScript代码页中?

1) Do I put the link to the jQuery code within the html head? Or within my JavaScript code page?

2)此代码在哪里? html页面,还是我的JavaScript页面?

2) Where does this code go? The html page, or my JavaScript page?

$(document).ready(function(){
    //Code here
});

3)上面,'代码在这里',它们意味着JavaScript代码,对吗?不是我的HTML代码?

3) Above, by 'code here', they mean JavaScript code, right? Not my html code?

4)我已经阅读了关于在html页面底部初始化JavaScript代码的内容。从我的观点来看,我不必使用jQuery的.ready函数,对吗?

4) I've read about initializing JavaScript code at the bottom of an html page. From what I take though, I don't have to do that with jQuery's .ready function, right?

推荐答案


  1. 您希望JavaScript文件位于< head> 或结束< / body> tag。

  2. 代码可以去任何地方,但我建议使用外部JavaScript页面。


  3. 这是正确的。

  1. You should like to your JavaScript files either in the <head> or above the closing </body> tag.
  2. The code can go anywhere really, but I would suggest an external JavaScript page.
  3. Yes
  4. This is correct.

这篇关于我在哪里放$(文件).ready()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆