gpt4 book ai didi

php - 当我不把它放在 jQuery(document).ready 中时,jquery 不工作

转载 作者:行者123 更新时间:2023-11-30 13:27:55 25 4
gpt4 key购买 nike

jQuery(document).ready(function(){
jQuery(".test").click(function() {
alert(1);
});
});

当我尽量不放:

jQuery(".test").click(function() {
alert(1);
});

jQuery(document).ready() 中它不会工作。

您认为造成这种情况的原因是什么?我已经加载了具有该功能的自定义脚本。

<script type="text/javascript" src="/scripts/js/jquery.js"></script>
<script type="text/javascript" src="/scripts/js/customScript.js"></script>

任何答案将不胜感激和奖励。

谢谢!

最佳答案

如果您在 <head> 中加载它,然后是你的 .test在您的代码执行时尚未加载。因此,jQuery(".test")返回 [] , 所以 click事件没有附加任何东西。如果你移动你的 <script> <body> 中的最后一件事,它应该可以工作。

关于php - 当我不把它放在 jQuery(document).ready 中时,jquery 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7844063/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com