$和jQuery有什么区别 [英] What is the difference between $ and jQuery

查看:134
本文介绍了$和jQuery有什么区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试在$(document).ready中使用$("#div_id")时,它返回NULL,但是当我使用jQuery("#div_id")时,它返回实际的对象!

When I try to use $("#div_id") in $(document).ready it returns NULL, but when I use jQuery("#div_id") it returns the actual object!

为什么会这样?

更新:我尝试了noConflict方法,但未获得任何提示.

UPDATE: I tried noConflict method without gaining any hints.

jQuery.noConflict()
function (a,b){return new c.fn.init(a,b)}

$.noConflict();
TypeError: Object function ()
    {
        return document.getElementById.apply(document, arguments)
    } has no method 'noConflict'

更新2:

$(document).ready(function() {
    debugger;
});

<input type="text" id="test" name="test" value="123" />

当我在控制台中运行以下代码时,我得到了这些结果:

When I run the following code in the console i got those results:

$("#test").val()
TypeError: Cannot call method 'val' of null
jQuery("#test").val()
"123"

谢谢

推荐答案

请参见 jQuery.noConflict().页面上的其他JavaScript库是否可以使用$变量?

See jQuery.noConflict(). Could other javascript libraries on your page be using the $ variable?

$只是用于别名jQuery的变量,并且是变量,可以为其分配任何内容.

$ is just a variable that is used to alias jQuery and being a variable, anything could be assigned to it.

这篇关于$和jQuery有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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