0

私が使用するとき、私は$("input[type=text]")絶対にすべてのテキストボックスを意味しますが、タイプが設定されている入力のみを返します。

例:

<input name="text1" />
<input name="text2' type="text"/>

text1含まれていません。

タイプが設定されているかどうかに関係なく、すべてのテキスト入力を取得する方法は?

4

5 に答える 5

5

type=text のものと、type 属性のないものを選択します。

$("input[type=text],input:not([type])")
于 2012-10-12T20:55:17.613 に答える
4
$('input:text')

公式ドキュメントから:

jQuery 1.5.2 以降、:text は指定された type 属性を持たない入力要素を選択します (この場合、type="text" が暗示されます)。

于 2012-10-12T20:56:40.163 に答える
2

filter次の方法を使用できます。

$("input").filter(function(){
    return this.type === 'text'
})​

http://jsfiddle.net/hgzmQ/

于 2012-10-12T20:56:02.443 に答える
0

If you don't set the type, then [type="text"] will preclude the ones without type.

if you select $('input') you will get every input regardless of type, so that could be a text field, or not. but it would still apply to every input field.

If you don't set the type, it won't be shown as type=text, but it will be rendered as such. That means you can't select JUST [type="text"], but you could always preclude others though as follows:

$('input[type=text]','input:not([type])')

Not sure if this helps at all.

于 2012-10-12T21:01:54.850 に答える
0

入力のすべての名前に「テキスト」が含まれている場合 (そうでない場合、それがテキスト ボックスであることをどのように理解できますか?)、試すことができます。

$('input[name*="text"]');
于 2012-10-12T20:54:26.313 に答える