为什么有时候jQuery选择器会返回类似“a.fn.init”的内容? [英] Why sometimes jQuery selector returns something like "a.fn.init"?

查看:1280
本文介绍了为什么有时候jQuery选择器会返回类似“a.fn.init”的内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道我的Chrome浏览器会发生什么情况,但突然间在控制台中执行 $('div#my')的行为完全不同于之前。有一次,我经历了这一点,但后来它不知怎么恢复,所以我不知道如何重现它,今天它再次发生。



请观看视频: http://peaceevertvimg.org/jq.php



在视频中,我在两个不同的浏览器中执行 $('div#my')



第一个浏览器不是chrome,但我相信它使用了chrome的内核,所以它的行为就是我所期望的,因为目前我的chrome没有按预期工作,所以我必须使用它展示我的期望:当您执行 $('div#my )`时,您直接看到html标签,并且您可以轻松看到标签的html内容,在这种情况下。



相反,在我的chrome浏览器中,结果是不同的,当我做 $('div#my')我看到一个对象( n.fn.init ),我不能立即看到某些东西,这当然是非常不方便的。但在此之前,我非常肯定它不是这样,这种行为与第一个浏览器完全相同。



本视频中的简单网页是 http://peaceevertvimg.org/jquery.php ,你可以在Chrome浏览器中去测试自己。我很肯定你们中的大多数人都不会看到我的视频中显示的结果。我的Chrome浏览器发生了什么变化?(我禁用了所有扩展并将其更新到最新版本)

解决方案

如果您打开Chrome的开发人员工具控制台的任何给定页面,只需调用 $ 您应该看到

  $(selector,[startNode]){[Command Line API]} 

如果你这样做在加载了jQuery的页面上,你会看到

  function(a,b){return new n.fn. init(a,b)} 

评估 $($ 0)将取决于给定上述信息的页面上下文。您将获得元素引用或jQuery对象。


I don't know what happen to my Chrome browser, but all of sudden the behavior of doing $('div#my') in console is totally different from before. One time I've experienced this but later it somehow recovered, so I don't know how to reproduce it, and today it happened again.

Please watch the video:http://peaceevertvimg.org/jq.php.

In the video I do $('div#my') in two different browsers:

the first browser is not chrome but I believe it uses the chrome's kernel so its behavior is what I expect, and because currently my chrome is not working as expected so I have to use it to demonstrate my expection: when you do $('div#my)` you see directly the html TAG, and you can easily see the tag's html content, which is "something" in this case.

In contrast, in my chrome browser, the result is different, when I do $('div#my') I see an Object(n.fn.init), and I can't see the "something" immediately, which of course is very inconvenient. But before, I am pretty sure it was not like this, the behavior WAS exactly like that in the first browser.

The simple webpage in this video is http://peaceevertvimg.org/jquery.php, you can go test for yourself in chrome browser. And I am pretty sure most of you won't see the result as shown in my video. What happened to my chrome?(I've disabled all expansions and updated it to the latest version)

解决方案

If you open Chrome's developer tools console for any given page and simply invoke $ you should see

$(selector, [startNode]) { [Command Line API] }

If you do the same thing on a page that has jQuery loaded, you'll see

function (a,b){return new n.fn.init(a,b)}

Evaluating $($0) is going to depend on the context of the page given the above information. You'll either get an element reference or a jQuery object.

这篇关于为什么有时候jQuery选择器会返回类似“a.fn.init”的内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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