Home > Article > Web Front-end > Common codes for jquery form value_jquery
jquery operation form element code
/*
Suppose there is a button id="save"
$(document).ready(function(){
$("# save").click(function(){
$("#save") .attr("disabled",true);//Set as disabled submit();//It doesn’t matter if you have many forms with ID form1, only the first one will be submitted haha.
});
});
Get the text of the selected item in the drop-down menu ;
Get and set the value of the drop-down menu;
Clear the drop-down menu;
Add elements to the following menu;
Get the radio button value;
Select the radio or check button;
Get the check box value;
Judge whether the radio or check box is selected;
Judge whether the element is available or not;
Judge whether the element is available or not.
1. Remove the text of the selected item in the drop-down menu
$("#select option[selected]").text();//There is a space between select and option, option is a child element of select$("#select option:selected").text ();//If written as $("#select").text(); it will select the text of all drop-down menus
2. Get and set the value of the drop-down menu
$("#select").val();//Get the value
$("#select") .val("value");//Set, if there is an option with the value value in the select, the option will be selected. If it does not exist, the select will not make any changes
3. Clear the drop-down menu
$("#select").empty();
$("#select").html("");
4. Add elements to the following menu
$('').appendto($("#select "));
$("#select").append('');
5. Get the radio button value
$("#id[checked]").val();
6. Selection of radio or check button
$("#id[value=val]").attr("checked",true);//Select
$("#id[value=val]").attr("checked","");//Cancel selection
$("#id[value=val]").attr("checked ",false);//Cancel the selection
$("#id[value=val]").removeattr("checked");//Cancel the selection
7. Get the checkbox value
$("input[type=checkbox][checked]").each(function(){
alert($( this).val());
})
//If you use $("input[type=checkbox][checked]").val(), only the first selected value will be returned
8. Determine whether the radio or check box is selected
if($("#id").attr("checked")){}//Determine whether it is selected
if($("#id").attr("checked")==true){}//Judge selected
if($("#id").attr("checked")== undefined){}//Judge not selected
9. Whether the element is available or not
$("#id").attr("disabled",false);//Set to available
$("# id").attr("disabled",true);//Set as disabled
10. Determine whether an element is available or not
if($("#id").attr("disabled")){}//Judge if it is not available
if ($("#id").attr("disabled")==undefined){}//Judge available