亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

jQuery form selector

Whether it is submitting or transmitting data, the role of form elements in dynamic interactive pages is very important. A form selector has been specially added to jQuery, which makes it extremely convenient to obtain a certain type of form element.

Specific method description of the form selector:

333.png


Note:

Except for the input filter selector, almost every form category filter corresponds to the type value of an input element. Most form category filters can be replaced with attribute filters. For example, $(':password') == $('[type=password]')

If you want to get the number of form elements in the form, the code is as follows:

$("#form1  :input").length;        //注意與$("#form1   input")的區(qū)別

If you want to get the number of form elements in the form The number of single-line text boxes, the code is as follows:

$("#form1   :text").length;

If you want to get the number of password boxes in the form, the code is as follows:

$("#form1   :password").length;

Similarly, the operation of other form selectors is similar to this

Get all <p> elements in the page, and add an onclick event to each <p> element, for example:

$("p").click(function({
            //doing somethingr(操作)
})

Get the element with the id tb, Then look for the tbody tag below it, and then look for the tr element with an even index value under tbody to change its background color (css("property", "value"); used to set the style of the jQuery object). For example:

$('#tb tbody tr:even').css("backgroundColor","#888");

First use the attribute selector, then use the form object attribute to filter, and finally get the jQuery object Length, for example:

$('#btn').click(function(){
                  var   length=$("input[name='check']:checked").length;
                  alert("選中的個(gè)數(shù)為:"+length);
})

Clear all input type="text" text box content: $("input:text").val("");


Continuing Learning
||
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-type" content="text/html; charset=utf-8" /> <title></title> <style> input{ display: block; margin: 10px; padding:10px; } </style> <script src="http://code.jquery.com/jquery-3.1.1.min.js"></script> <style> input{ display: block; margin: 10px; padding:10px; } </style> </head> <body> <h2>子元素篩選選擇器</h2> <h3>input、text、password、radio、checkbox</h3> <h3>submit、image、reset、button、file</h3> <div class="left first-div"> <form> <input type="text" value="text類型"/> <input type="password" value="password"/> <input type="radio"/> <input type="checkbox"/> <input type="submit" /> <input type="image" /> <input type="reset" /> <input type="button" value="Button" /> <input type="file" /> </form> </div> <script type="text/javascript"> //查找所有 input, textarea, select 和 button 元素 //:input 選擇器基本上選擇所有表單控件 $(':input').css("border", "1px groove red"); </script> <script type="text/javascript"> //匹配所有input元素中類型為text的input元素 $('input:text').css("background", "#A2CD5A"); </script> <script type="text/javascript"> //匹配所有input元素中類型為password的input元素 $('input:password').css("background", "yellow"); </script> <script type="text/javascript"> //匹配所有input元素中的單選按鈕,并選中 $('input:radio').attr('checked','true'); </script> <script type="text/javascript"> //匹配所有input元素中的復(fù)選按鈕,并選中 $('input:checkbox').attr('checked','true'); </script> <script type="text/javascript"> //匹配所有input元素中的提交的按鈕,修改背景顏色 $('input:submit').css("background", "#C6E2FF"); </script> <script type="text/javascript"> //匹配所有input元素中的圖像類型的元素,修改背景顏色 $('input:image').css("background", "#F4A460"); </script> <script type="text/javascript"> //匹配所有input元素中類型為按鈕的元素 $('input:button').css("background", "red"); </script> <script type="text/javascript"> //匹配所有input元素中類型為file的元素 $('input:file').css("background", "#CD1076"); </script> </body> </html>
submitReset Code