Selecting Textbox in a form
I have the following query:
$("input:text").somefunction();
How can I also include a button and Textarea in the abov开发者_开发技巧e code without using classes?
:text
filters the inputs for text-boxes, so simply selecting :input
will get what you're after:
Selects all input, textarea, select and button elements.
note that this is a bit confusing: $('input')
selects all <input>
elements (buttons too, but not textareas), but $(':input')
gets what you want.
, which takes just a single element according to structure of the whole document.
-->
You can include extra elements by adding commas.
$('#myForm input:text:eq(9), #myForm input:button, #myForm input:textarea').someFunction();
Besides the usual approach of expanding your selector with commas, you can use add
:
$('#form :input:text:eq(9)')
.add('#form textarea')
.add('#form :input:button')
.add('anything_else')
.somefunction();
Note however that :input
alone will select all your form elements.
Reference: :input selector
精彩评论