Home > Web Front-end > JS Tutorial > Summary of common jquery operations on radio button, multi-select box, text box and other operations_javascript skills

Summary of common jquery operations on radio button, multi-select box, text box and other operations_javascript skills

WBOY
Release: 2016-05-16 17:04:51
Original
1282 people have browsed it

1. Text boxes, radio buttons, check boxes, related operations

Copy code The code is as follows:

var sex=$("input[name='sex']:checked").val(); //Get a set of radio selected items The value of
var item=$("#sel option:selected").text(); //Get the text of the selected item in select
var option_num=$('#sel').val(); // Get the Select project index
$ ("#SEL") [0] .selectEdindex = 1; // The second element of the selecting drop -down box is the current selection value
$ ("input [name = 'sexx sex ']").get(1).checked=true; //The second element of the radio radio selection group is the currently selected value

Or set the default selection for the radio button:
$("input[name='sex']").each(function(){
      if($(this).val()= =s){
                   $(this).attr("checked", true);                                                              🎜>

Jquery sets the default selected item in the drop-down list (select) based on the value value



Copy code
The code is as follows:
< ;script>
function bao(s)
{
txt.value=s;
//After selection, let the first item be selected, so that there is Change.
document .all.sel.options[0].selected=true;
}






2. jQuery gets the Text and Value selected by Select


Copy code
The code is as follows : Syntax explanation: $("#select_id").change(function(){//code...}); //Add an event for Select, when one of them is selected Triggered when selecting an item
var checkText=$("#select_id").find("option:selected").text(); //Get the Text selected by Select
var checkValue=$("#select_id") .val(); //Get the Value selected by Select
var checkIndex=$("#select_id ").get(0).selectedIndex; //Get the index value selected by Select
var maxIndex=$(" #select_id option:last").attr("index"); //Get the maximum index value of Select


jQuery sets the Text and Value selected by Select:
Syntax explanation:

$("#select_id ").get(0).selectedIndex=1; //Set the Select index value Select the item of 1 $("#select_id ").val(4); //Set the Value value of Select to 4 to select the item
$("#select_id option[text='jQuery']" ).attr("selected", true); //Set the Text value of Select to the jQuery item selected


jQuery adds/removes the Option item of Select:

Syntax explanation:

$("#select_id").append("

Copy code The code is as follows:






jQuery common




Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template