jQuery选择器在控制台中不起作用 [英] jQuery selectors don't work in console

查看:146
本文介绍了jQuery选择器在控制台中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不能为我的生活工作这一个。我有js正在运行,'container state ..'是来自页面上运行的js的控制台日志。它正在显示一个选择器,但如果我想在控制台中做任何事情,它只返回null。我假设某种程度上我在某处编写jQuery函数,好像我调用了jQuery

I can't for the life of me work this one out. I have js running and 'container state..' is a console log from the running js on the page. It's displaying a selector, but if i want to do anything within the console it just returns null. I'm assuming somehow i'm over writing jQuery function somewhere, as if i called jQuery

>>> $
function()

这就是我调用选择器的方式

This is how i am calling a selector

Container state 3 jQuery(div.module-carousel)
>>> $('body')
null  


推荐答案

jQuery使用2个名称空间, jQuery $ 。另一个库可以使用 $ 。尝试使用 jQuery 而不是 $ (假设它也没有被覆盖):

jQuery uses 2 namespaces, jQuery and $. Another library could have used the $. Try using jQuery instead of $ (assuming that it isn't overridden as well):

jQuery('body');

或在即时函数中包装jQuery并使用 $ 在其中,所以你不需要在现有代码中替换 $

or wrap jQuery in an immediate function and use $ in it so you don't need to replace $ in the existing code:

(function($){
    //"$" in here is jQuery
    //code that uses $ as jQuery will work in here
}(jQuery)); //pass in jQuery and execute

这篇关于jQuery选择器在控制台中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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