Home > Article > Web Front-end > jquery form filter
Form filter
1 Select form control elements according to type
css writing method, only all inputs are selected, other controls cannot be selected
$('input').css('background-color', 'lightgreen')
jquery To write, just add a colon in front of it. Except for input, select, button, and textarea, you can select
$(':input').css('background-color', 'lightgreen')
. If you only want to select the input tag, add the tag limit: input before: input. At this time It is completely consistent with the effect of css syntax
$('input:input').css('background-color', 'lightgreen')
: input: The original intention is to select all form controls. You can use css attributes to restrict it later, such as getting the password box
$(':input[type="password"]').css('background-color', 'lightgreen')
In addition to using css later In addition to attribute restrictions, it is more recommended to use jquery filters. For example, the password box filter is: password
$(':input:password').css('background-color', 'lightgreen')
Change the color to show the difference. As can be seen from here, chain operations are also supported between filters
$(':input:password').css('background-color', 'skyblue')
Let’s do a few more exercises
2. Select elements based on the characteristics of the form control
:input, only select form elements, excluding:file,:image, :input We have already done this
Select only the file type
$(':file').css('background-color', 'lightgreen')
Select only the text box:type="text"
$(':text').css('color',"red")
Select only the submit button
$('button:submit').css({ 'background-color':'orange', 'color':'white', 'font-size':'1.2em', 'border': 'none', 'width':'90px', 'height':'40px' })
The above is the detailed content of jquery form filter. For more information, please follow other related articles on the PHP Chinese website!