Home  >  Article  >  Web Front-end  >  Common codes for jquery form value_jquery

Common codes for jquery form value_jquery

WBOY
WBOYOriginal
2016-05-16 18:38:31859browse

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


Text box operation Value: var textval = $("#text_id").attr("value");
var textval = $("#text_id").val();
Clear content: $("#txt").attr ("value",");
Fill content: $("#txt").attr("value",'123′);


Text field operations
Value: var textval = $("#text_id").attr("value");
var textval = $("#text_id").val();
Clear content: $("# txt”).attr(”value”,”);
Fill content: $(”#txt”).attr(”value”,'123′);


Radio button Operation
value: var valradio = $("input[@type=radio][@checked]").val(); //When there is only one set of Radio
var valradio =$( 'input[@name=chart][@checked]').val(); //In the case of multiple groups of Radio, take the value of one group according to the name


Drop-down box operation Value: var selectval = $('#sell').val();
Set selection: $("#select_id").attr("value",'test');//Set value= The test item adds a new item to the currently selected item
: $(""). appendTo("#select_id")//Add the option of the drop-down box
Clear the drop-down box: $("#select_id").empty();//Clear the drop-down box


Multi-select box Operation
value: $("#chk_id").attr("checked",'');//Unchecked value
$("#chk_id").attr("checked" ,true);//Selected value
if($("#chk_id").attr('checked')==undefined) //Determine whether it has been selected
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn