javascript DOM 对象不会成为 jQuery 对象

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22504967/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 23:16:35  来源:igfitidea点击:

DOM object not becoming a jQuery object

javascriptjquery

提问by Maximus S

How come I cannot make $(frame) a jQuery object in the below case? Below is my output from chrome developer tools.

为什么我不能在下面的情况下将 $(frame) 变成一个 jQuery 对象?以下是我从 chrome 开发人员工具中得到的输出。

console: mainFrame
output: <frame src=?"http:?/?/someurl.com" name=?"mainFrame">?
console: $(mainFrame).contents()
output: SyntaxError: Failed to execute 'querySelector' on 'Document': '[object HTMLFrameElement]' is not a valid selector.

Edit:

编辑:

to respond to comments...

回复评论...

$.toString()
"function $(selector, [startNode]) { [Command Line API] }"

typeof(mainFrame)
"object"

jQuery
ReferenceError: jQuery is not defined

回答by Aegis

jQuery doesn't seem to be included in your document. Some browsers set $to querySelectorby default (which is a native way to select elements of the DOM using css-like syntax), thereby your error message. Try adding

jQuery 似乎没有包含在您的文档中。一些浏览器默认设置$querySelector(这是使用类似 css 的语法选择 DOM 元素的本机方式),因此您的错误消息。尝试添加

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>

回答by Touseef Murtaza

Looks like jQuery is not included into the DOM, try to include jQuery either by CDN or add standalone jQuery into the DOM.

看起来 jQuery 没有包含在 DOM 中,尝试通过 CDN 包含 jQuery 或将独立的 jQuery 添加到 DOM 中。

You can confirm the jQuery installation by typing $into the browser inspect tab.If the output is something like

您可以通过$浏览器检查选项卡中键入来确认 jQuery 安装如果输出类似于

> $
? (e,t){return new x.fn.init(e,t,r)}

then jQuery added successfully.

然后jQuery添加成功。

回答by eyurdakul

Try

尝试

$(frame).contents();

Or

或者

$("html", frame);

not sure which one will work.

不确定哪一个会起作用。