获得所有输入与类型文本在控制台?页面在iFrame



如何将页面上的所有inputs的形式转换为数组,同时通过输入类型(文本|复选框|单选)进行匹配?

<标题> JavaScript:

像这样简单的js就能得到所有的inputs

var inputs = document.getElementsByTagName( 'input' );

现在使用jQuery:

我已经加载了jQuery,我尝试:按照docs (http://api.jquery.com/text-selector/)

$( "<input>" ).is( ":text" ); 
$( "<input>" ).is( "[type=text]" ); 

控制台错误信息:

TypeError: undefined is not a function
message: "undefined is not a function"
stack: (...)
get stack: function () { [native code] }
set stack: function () { [native code] }
__proto__: Error
<标题>附加信息:

我试图获得text输入的页面在iFrame中,整个交互作用在webkit中运行。

    我的主页已经加载了jQuery。
  • iFrame页面没有。

需要得到iFrame页面的输入与jQuery从我的主页

要使用jQuery选择输入,您可以这样做

$("input")

不需要括号

选择所有文本输入

$("input[type='text']")

通过编辑引起的问题的变化,您可以在这里找到答案:在iFrame中选择元素jQuery

给出的答案是准确的但是你也可以使用

$(':text")

会给你所有的文本输入项,在我看来更容易读。@ robert的回答还是很准确的

选择所有type="text"的输入:

$(':text')

输入类型="checkbox"使用:

$(':checkbox')

type="radio"的输入:

$(':radio')

EDIT以迎合新的iframe信息

对于iframe中的输入,它们分别转换为:

$('iframe').contents().find( ':text' );
$('iframe').contents().find( ':checkbox' );
$('iframe').contents().find( ':radio' );

最新更新