drop-down box
<SelectID= "CategoryId"Data-placeholder= "Asset Type"style= "width:350px;" > <optionvalue= "1">Hard disk</option> <optionvalue= "2">Motherboard</option> <optionvalue= "3">Cpu</option> <optionvalue= "4">Card</option>
1. Set the dropdown box "hard Disk" as selected
$ ("#CategoryId"). Val ("1"); $ ("#CategoryId"). Find ("option[text= ' HDD ']"). attr ("selected",true);
$ ("#CategoryId"). Get (0). attr ("selected",true);
2. Get the value of the drop-down box
$ ("#CategoryId"). Val (); #1 $ ("#CategoryId"). Find ("option:selected"). Text (); # "HDD"
3. Cascade for Select
There are many times when a select cascade is used, that is, the value of the second select changes with the value selected in the first select.
such as: $ (". Selector1"). Change (function () {
Clear the second one first.
$ (". Selector2"). empty ();
In real-world applications, the option here is typically generated by looping multiple
var option = $ ("<option>"). Val (1). Text ("Pxx");
$ (". Selector2"). Append (option);
});
$ ("#DestIdcpName"). Change (function() { $("#id"). empty (); $.ajax ({url:url, type:"POST", data:{"Params":p Arams}, DataType:"JSON", Success:function(list) {if(list. Return = = 0) {List=list. Data; $("#" +id). Append ("<option value=" ></option> "); for(vari = 0; i < list.length; i++) { varo = "<option value=" "+ list[i][column" + ">" + list[i][column] + "</option>"; $("#id"). Append (o); } return true; }}, Error:function(list) {alert (list.message); return false; } }); return true; });
check box
<label><inputtype= "checkbox"ID= "Checkall" />Select All/Select All</label><label><inputname= "Fruit"type= "checkbox"value= "1" />Apple</label><label><inputname= "Fruit"type= "checkbox"value= "1" />Apple</label> <label><inputname= "Fruit"type= "checkbox"value= "2" />Peach</label> <label><inputname= "Fruit"type= "checkbox"value= "3" />Banana</label> <label><inputname= "Fruit"type= "checkbox"value= "4" />Pear</label>
1. check box select all/Reverse Selection
You can use prop or attr .
$ ("[name=' checkbox ']"). attr ("Checked", ' true ');
$ ("[name=' Fruit ']"). Prop ("Checked", ' true ');
/*checkbox for full selection and inverse selection*/ $(' #checkAll '). Live (' click ',function(){ if($( This). Prop (' checked ') ) {$ ("[Name= ' Fruit ']"). each (function(){ $( This). Prop (' checked ',true); }); }Else{$ ("[Name= ' Fruit ']"). each (function(){
$( This). Prop (' checked ',false);
}); } });
2. Disable checkbox
true }); #or $ (true });
3. Set the selected
$ ("Input[name= ' Fruit '][value=3]"). Prop ("Checked", ' checked '); $ ("input[name= ' Fruit '][value=3]"). Prop ("Checked", "'); $ (true
4. Get the selected value
$ ("[name= ' Fruit ']"). each (function() { if($ (this). Prop (' checked ')) { alert (this). Val ()); } });
Radio Box
<label><inputname= "IsAvailable"type= "Radio"value= "2" />Pending test</label> <label><inputname= "IsAvailable"type= "Radio"value= "1" />Is</label> <label><inputname= "IsAvailable"type= "Radio"value= "0" />Whether</label>
1. Set the selected
true; // check "pending test" true; // check "pending test"
2. Get the value
// 2 // pending Test
3. Disable
// "Pending test" prevents selection
jquery Actions for drop-down boxes and radio boxes