Syntax Explanation:
1 |
$( "#select_id" ).change( function (){ //code...}); //为Select添加事件,当选择其中一项时触发 |
2 |
var checkText=$( "#select_id" ).find( "option:selected" ).text(); //获取Select选择的Text |
3 |
var checkValue=$( "#select_id" ).val(); //获取Select选择的Value |
4 |
var checkIndex=$( "#select_id " ).get(0).selectedIndex; //获取Select选择的索引值 |
5 |
var maxIndex=$( "#select_id option:last" ).attr( "index" ); //获取Select最大的索引值 |
jquery sets the text and value selected for select:
Syntax Explanation:
1 |
$( "#select_id " ).get(0).selectedIndex=1; //设置Select索引值为1的项选中 |
2 |
$( "#select_id " ).val(4); //设置Select的Value值为4的项选中 |
3 |
$( "#select_id option[text=‘jQuery‘]" ).attr( "selected" , true ); //设置Select的Text值为jQuery的项选中 |
jquery Add/Remove option for select:
Syntax Explanation:
1 |
$( "#select_id" ).append( "<option value=‘Value‘>Text</option>" ); //为Select追加一个Option(下拉项) |
2 |
$( "#select_id" ).prepend( "<option value=‘0‘>请选择</option>" ); //为Select插入一个Option(第一个位置) |
3 |
$( "#select_id option:last" ).remove(); //删除Select中索引值最大Option(最后一个) |
4 |
$( "#select_id option[index=‘0‘]" ).remove(); //删除Select中索引值为0的Option(第一个) |
5 |
$( "#select_id option[value=‘3‘]" ).remove(); //删除Select中Value=‘3‘的Option |
6 |
$( "#select_id option[text=‘4‘]" ).remove(); //删除Select中Text=‘4‘的Option |
jquery Radio value, checkbox value, select Value, Radio selected, CheckBox selected, select selected, and its related to get a set of radio values of the selected item
1 |
var item = $( ‘input[@name=items][@checked]‘ ).val(); |
Gets the text of the Select selected item
1 |
var item = $( "select[@name=items] option[@selected]" ).text(); |
The second element of the Select drop-down box is the currently selected value
1 |
$( ‘#select_id‘ )[0].selectedIndex = 1; |
Radio the second element of a radio group is the currently selected value
1 |
$( ‘input[@name=items]‘ ).get(1).checked = true ; |
Get Value:
- text box, text area: $ ("#txt"). attr ("value");
- Multi Box checkbox:$ ("#checkbox_id"). attr ("value");
- Radio Group Radio: $ ("input[@type =radio][@checked]"). Val ();
- Drop-down box select: $ (' #sel '). Val ();
Control form elements:
text box, text area:
$ ("#txt"). attr ("Value", "");//Clear Contents
$ ("#txt"). attr ("value", ' 11 ');//fill content
Multiple marquee checkbox: $ ("#chk1"). attr ("Checked", "");//No Tick
$ ("#chk2"). attr ("Checked", true);//tick
if ($ ("#chk1"). attr (' checked ') ==undefined)//Determine if a tick has been made
Radio Group Radio: $ ("input[@type =radio]"). attr ("Checked", ' 2 ');//Set value=2 for the currently selected item
Drop-down box select: $ ("#sel"). attr ("value", '-sel3 ');//Set the VALUE=-SEL3 item as the current selection
$ ("<option value= ' 1 ' >1111</option><option value= ' 2 ' >2222</option>"). AppendTo ("#sel")// option to add a drop-down box
$ ("#sel"). empty ();//Empty drop-down box
Traverse option and Add, remove option
01 |
function changeShipMethod(shipping) { |
02 |
var len = $( "select[@name=ISHIPTYPE] option" ).length |
03 |
if (shipping.value != "CA" ) { |
04 |
$( "select[@name=ISHIPTYPE] option" ).each( function () { |
05 |
if ($( this ).val() == 111) { |
10 |
$( "<option value=‘111‘>UPS Ground</option>" ).appendTo($( "select[@name=ISHIPTYPE]" )); |
Gets the selected value of the drop-down box
$ (#testSelect option:selected '). Text ();
or $ ("#testSelect"). Find (' option:selected '). Text ();
or $ ("#testSelect"). Val ();
check box, we recommend the following Operation method
$ ("#chk2") [0].checked = true;
$ ("#chk2") [0].checked = false;
Transferred from: http://www.cnblogs.com/shiyou00/p/5577329.html
JQuery Radio value, checkbox value, select Value