jQuery无法调用方法';获取';空的

jQuery无法调用方法';获取';空的,jquery,Jquery,我得到一个无法调用null的方法“get” 它在JSFIDLE中工作: var divs=$(“div.Image”).get().sort(函数()){ 返回Math.round(Math.random())-0.5;//random,这样我们就得到了正确的+/-组合 }).切片(0,1) $(divs).appendTo(divs[0].parentNode.show(); 有时浏览器假装很好地加载jQ,而没有封装在块中。尝试使用$(document).ready(function(){首

我得到一个无法调用null的方法“get”

它在JSFIDLE中工作:


var divs=$(“div.Image”).get().sort(函数()){
返回Math.round(Math.random())-0.5;//random,这样我们就得到了正确的+/-组合
}).切片(0,1)
$(divs).appendTo(divs[0].parentNode.show();

有时浏览器假装很好地加载jQ,而没有封装在块中。尝试使用
$(document).ready(function(){
首先阻塞)。如果这不能解决您的问题,那么jQ也有可能与其他东西发生冲突,因此请尝试使用jQuery()更改所有$()调用。

尝试将脚本更改为:

<script>
$(document).ready(function() {

    var divs = $("div.Image").get().sort(function() {
               return Math.round(Math.random())-0.5; //random so we get the right +/-              combo
               }).slice(0,1)

    $(divs).appendTo(divs[0].parentNode).show();
});
</script>

$(文档).ready(函数(){
var divs=$(“div.Image”).get().sort(函数()){
返回Math.round(Math.random())-0.5;//random,这样我们就得到了正确的+/-组合
}).切片(0,1)
$(divs).appendTo(divs[0].parentNode.show();
});

这将允许您的脚本等待DOM完成加载后再执行。

有时,jquery假装很好地加载jQ,而没有封装在块中。请尝试使用
jquery.(document).ready(function(){
block first。并使用正确的jquery,如

<script>
$(document).ready(function() {

    var divs = $("div.Image").get().sort(function() {
               return Math.round(Math.random())-0.5; //random so we get the right +/-              combo
               }).slice(0,1)

    $(divs).appendTo(divs[0].parentNode).show();
});
</script>