Drop-down box:
//Get the text of the selected item in the drop-down menu (note the space in the middle)
var cc1 = $(".formc select[@name='country'] option[@selected]").text() ;
//Get the value of the selected item in the drop-down menu
var cc2 = $('.formc select[@name="country"]').val();
//Get the value of the drop-down menu ID attribute value of the selected item
var cc3 = $('.formc select[@name="country"]').attr("id");
//Clear the drop-down box//
$ ("#select").empty();$("#select").html('');
//Add the option of the drop-down box
$("
A little explanation:
select[@name='country'] option[@selected]
represents the option element with the selected attribute inside the select element that has a name attribute and the attribute value is 'country'. It can be seen that anything starting with @ means that what follows is an attribute.
Radio button:
//Get the value of the selected item of the radio button (note that there is no space in the middle)
$("input[@type=radio][@checked]").val();
//Set The radio button value=2 is selected. (Note that there is no space in the middle)
$("input[@type=radio][@value=2]").attr("checked",'checked');
Checkbox:
//Get the value of the first selected item of the check box
$("input[@type=checkbox][@checked]").val();
//Because of the check box Generally, multiple items are selected, so you can loop through the output
$("input[@type=checkbox][@checked]").each(function(){
alert($(this).val() );
});
//Unchecked
$("#chk1").attr("checked",'');
//Checked
$(" #chk2").attr("checked",true);
//Determine whether it has been checked
if($("#chk1").attr('checked')==undefined){}