Jquery operations select daqo

  • 2020-03-30 02:45:45
  • OfStack

Add a option


$('#id').append("<option value="value">Text</option>");//Append an option to the select
$('#id').prepend("<option value='0'>Text</option>");   //Insert an option for the select


Remove the option

$("#ID option").each(function(){
if($(this).val()==111){
$(this).remove();
}
});

$("<option value='111'>UPS Ground</option>").appendTo($("#ID"));
 Gets the selected value of the drop-down menu 
$("#testSelect option:selected").text();
$("#testSelect").find('option:selected').text();
$("#testSelect").val();
 According to the option Select the drop-down box 
$('#testSelect').val('111');

2. Menu:


$("input[@type=radio][@checked]").val();//Gets the value of the selected item in the marquee (note no space)
$("input[@type=radio][@value=2]").attr("checked",'checked');//Set the value of the marquee =2 to the selected state.
3, Check box :
$("input[@type=checkbox][@checked]").val();//Gets the value of the first item selected in the check box
$("input[@type=checkbox][@checked]").each(function(){//Because more than one check box is typically selected, the output can be looped
alert($(this).val());
});

$("#chk1").attr("checked",'');//Don't tick
$("#chk2").attr("checked",true);//  tick 
if($("#chk1").attr('checked')==undefined){}//Determine if you have checked the box
 Of course, jquery The selector is powerful .  There are many other ways .


<script src="jquery-1.2.1.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript">
$(document).ready(function(){
$("#selectTest").change(function()
{
alert($("#selectTest option[@selected]").text());
$("#selectTest").attr("value","2");

});
});
</script>

<a href="#">aaass</a>

<!-- A drop-down box -->
<select id="selectTest"name="selectTest">
<option value="1">11</option>
<option value="2">22</option>
<option value="3">33</option>
<option value="4">44</option>
<option value="5">55</option>
<option value="6">66</option>
</select>

Jquery radio values, checkbox values, select values, radio selected, checkbox selected, select selected, and related to get the values of a set of selected items of radio


varitem= $('input[@name=items][@checked]').val();

Gets the text of the selected item in a select


varitem= $("select[@name=items] option[@selected]").text();

The second element of the select drop-down box is the currently selected value


$('#select_id')[0].selectedIndex=1;

The second element of the radio radio group is the currently selected value


$('input[@name=items]').get(1).checked=true;

Get the value:
Text box, text area:


$("#txt").attr("value") ; 

Multi-checkbox:


$("#checkbox_id").attr("value") ; 

Radio group:


$("input[@type=radio][@checked]").val();

Drop-down box select:


$('#sel').val();

Control form elements:
Text box, text area:


$("#txt").attr("value",'');//Empty content
$("#txt").attr("value",'11');//Fill the content

Multi-checkbox:


$("#chk1").attr("checked",'');//Don't tick
$("#chk2").attr("checked",true);//  tick 
if($("#chk1").attr('checked')==undefined)//Determine if you have checked the box

Radio group:
$(" input [@ type = radio] "). The attr (" checked ", '2'); // the item with value=2 is the currently selected item
Drop-down box select:


$("#sel").attr("value",'-sel3');//The item with value=-sel3 is the currently selected item
$("<optionvalue='1'>1111</option><optionvalue='2'> 2222</option>").appendTo("#sel")//Add options to the drop-down box
$("#sel").empty() ; //Clear the drop-down box

Gets the values of a set of selected items of radio
The same code at the page code block index 4

Gets the text of the selected item in a select
The same code at the page code block index 5

The second element of the select drop-down box is the currently selected value
The same code at the page code block index 6

The second element of the radio radio group is the currently selected value
The same code at the page code block index 7

Get the value:
Text box, text area:
The same code at the page code block index 8

Multi-checkbox:
The same code at the page code block index 9

Radio group:
The same code at the page code block index 10

Drop-down box select:
The same code at the page code block index 11

Control form elements:
Text box, text area:
The same code at the page code block index 12

Multi-checkbox:
The same code at the page code block index 13

Radio group:


$("input[@type=radio]").attr("checked",'2');//The item with value=2 is the currently selected item

Drop-down box select:


$("#sel").attr("value",'-sel3');//The item with value=-sel3 is the currently selected item
$("<option value='1'>1111</option><option value='2'>2222</option>").appendTo("#sel")//Add options to the drop-down box
$("#sel").empty() ; //Clear the drop-down box


Related articles: