When making a form submission, if you are still submitting with form, the user experience is poor, so you generally use AJAX submissions.
Where you need to get the value of each form INPUT element and get it like a text box these are okay to say, jquery provides the. Val () method, which is easy to get, but getting the check box and radio button values is cumbersome.
There's nothing to do today. Encapsulates a function, the subsequent acquisition of the check box and radio button values only need to call this function, incoming jquery selector is OK, the following is attached to the function.
Function
/** * Get selected items for a single or set of input elements * incoming jquery selector * Support: text, return: literal * support: Hidden, return: Text * Support: password, return: Text * Support: TEXTAREA, return: Text * Support: Selec T, return: 1 * Support: checkbox, return: 1,2,3,4,5,6 * Support: Radio, return: 1 * 20161203*/functionGet_choose (choose) {varChoose_size =$ (choose). Size (); varChoose_type = $ (choose+ ': eq (0) '). attr (' type ')); varReturn_text = ' '; for(vari=0;i<choose_size;i++){ //If a check box or radio button requires special handling if(choose_type== ' checkbox ' | | choose_type== ' Radio '){ //determines whether the element is selected and is selected for processing if($ (choose+ ': eq (' +i+ ') '). Is (': Checked '))){ //If the check box is selected, get its value, continue to execute to get the next if(choose_type== ' checkbox ') {Return_text+ = (return_text!= ')? ', ' +$ (choose+ ': eq (' +i+ ') '). Val (): $ (choose+ ': eq (' +i+ ') '). Val (); } //If the radio button is selected, gets its value, terminates the loop Else if(choose_type== ' Radio ') {Return_text+ = $ (choose+ ': eq (' +i+ ') '). Val (); Break; } Else{ Break; } } } //other element attributes, returning their value directly, terminating the loop Else{Return_text+ = $ (choose+ ': eq (0) '). Val (); Break; } } returnReturn_text;}
Invocation mode
Alert (Get_choose (' [name= ' text box name name "]"),alert (get_choose (' [name= ' Text field name "]"); alert (Get_choose ( ' [name= ' multiple marquee name '] '); alert (Get_choose (' [name= ') (the name of the "Radio Box"]);
jquery Gets the selected item of a set of elements-functions, jquery Gets the check box value, jquery Gets the radio button value