In html, checkbox, radio, and select are used frequently during website development. These three controls can be used to select values. How can we select these controls. This article describes how to use jquery to obtain the selected values of these controls.
Jquery gets the radio selected value:
123
You can use either of the following methods:
$('input:radio:checked').val();$("input[type='radio']:checked").val();$("input[name='rd']:checked").val();
Jquery gets the selected select value:
option1 option2 option3 option4
Obtain the Value of the selected item:
$ ('Select # sel option: selected'). val (); or $ ('select # sel '). find ('option: selected'). val ();
Obtain the Text value of the selected item:
$ ('Select # seloption: selected'). text (); or $ ('select # sel '). find ('option: selected'). text ();
Obtain the index value of the selected item:
$('select#sel').get(0).selectedIndex;
Jquery gets the checkbox selected value:
checkbox1 checkbox2 checkbox3
Obtain the selected items of a single checkbox:
$ ("Input: checkbox: checked "). val () or $ ("input: [type = 'checkbox']: checked "). val (); or $ ("input: [name = 'ck ']: checked "). val ();
Obtain multiple checkbox selected items:
$('input:checkbox').each(function() { if ($(this).attr('checked') ==true) { alert($(this).val()); } });