当我把jquery库放在body之前时$(document).ready不工作 [英] $(document).ready is not working when i put jquery library before body
本文介绍了当我把jquery库放在body之前时$(document).ready不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
正常运作
<!DOCTYPE html>
< html>
< head>
< script src =http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js>
< / script>
< script>
$(document).ready(function(){
$(button)。click(function(){
$(p)。slideToggle();
});
});
< / script>
< / head>
< body>
< p>这是一个段落。< / p>
< button>在向上滑动和向下滑动p元素之间切换< / button>
< / body>
< / html>
但是当我搬家时
< script src =http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js>
在之前< body>
标签是它不起作用,因为我想把JavaScript放在底部,但是我不能把文件。在jquery库之后放入,这将是什么解决方案。
解决方案
<脚本>
window.onload = function(){
$(button)。click(function(){
$(p)。slideToggle();
}) ;
}
< / script>
It is working
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">
</script>
<script>
$(document).ready(function(){
$("button").click(function(){
$("p").slideToggle();
});
});
</script>
</head>
<body>
<p>This is a paragraph.</p>
<button>Toggle between slide up and slide down for a p element</button>
</body>
</html>
But when i move
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">
Before <body>
tag is it is not working, because i want Put JavaScript at bottom, but i can't put document.ready part after jquery library, what will be solution.
解决方案
<script>
window.onload = function() {
$("button").click(function() {
$("p").slideToggle();
});
}
</script>
这篇关于当我把jquery库放在body之前时$(document).ready不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文