document.ready 时没有警告消息 - jQuery
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8700735/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
No alert message when document.ready - jQuery
提问by red23jordan
This is my code:
这是我的代码:
$(document).ready(function() {
alert("I am an alert box!");
});
when I refresh the page, there is no alert box. Is there any wrong??
当我刷新页面时,没有警告框。有什么不对吗??
jQuery seems to be added correctly, but I am not able to get the alert for checking whether jQuery is working. Any ideas on how to make the alert show?
jQuery 似乎已正确添加,但我无法收到检查 jQuery 是否正常工作的警报。关于如何使警报显示的任何想法?
回答by Dennis Traub
Did you include the jQuery library before the call in your document?
您在文档中调用之前是否包含了 jQuery 库?
<script type="text/javascript"
src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
...
<script type="text/javascript">
$(document).ready(function() {
alert("I am an alert box!");
});
</script>
回答by T.J. Crowder
That should work provided you've loaded jQuery and you haven't used noConflict
. It works here, for instance.
如果您已经加载了 jQuery 并且您没有使用noConflict
. 例如,它在这里工作。
Without more information we can't really help, but here are some tips:
没有更多信息,我们无法真正提供帮助,但这里有一些提示:
- Look at your browser's JavaScript console for errors. Most likely there's a syntax error elsewhere on the page that's preventing the code you've quoted from ever being run.
- Make sure you've loaded jQuery correctly.
If you use
noConflict
, change$
tojQuery
in your code:jQuery(document).ready(function() { /* ... */ });
- 查看浏览器的 JavaScript 控制台是否有错误。很可能页面上的其他地方存在语法错误,导致您引用的代码无法运行。
- 确保您已正确加载 jQuery。
如果您使用
noConflict
,$
请jQuery
在您的代码中更改为:jQuery(document).ready(function() { /* ... */ });
回答by Nicola Peluchetti
That should definitely work. Be sure to have loaded jQuery before calling that snippets.
Take a look at the javascript console for any error
那应该肯定有效。请确保在调用该片段之前已加载 jQuery。
查看 javascript 控制台是否有任何错误
回答by redmoon7777
Some possibilities :
一些可能性:
- jquery is not inclided
- script tag has some typo
- you might have some other javascript which is creating the problem
- 不包括 jquery
- 脚本标签有一些错字
- 您可能还有其他一些 javascript 正在造成问题
回答by startupsmith
回答by Pradip R.
You just need to include jQuery File in your html page. put link given below in your html page and you ll have what you want :
您只需要在 html 页面中包含 jQuery 文件。把下面给出的链接放在你的 html 页面中,你就会得到你想要的: