JQuery gets examples of input checkbox radio and select by ID
- 2020-03-30 03:41:07
- OfStack
Input:
Var = $XXX (' # ID). Val ()
---------------------------------------------------------------------------------
The checkbox.
var xxx = [ ];
$('input[name=MyName]:checked).each(function(index, element) {
xxx.push($(element).val());
//Or XXX. Push ($(this). Val ());
});
Note: there is no ID based here. If your checkbox element is a child of a container (assuming the container's id is con_id), you can choose:
= = = = = =
$('#con_id input[name=MyName]:checked')
or
$('input[name=MyName]:checked', '#con_id')
----------------------------------------------------------------------------------
Radio:
Var = $XXX (' input [name = MyName] : checked "). The val ();
= = = = = =
Note: there is no ID based. To limit the specified ID, see the case of the checkbox above
----------------------------------------------------------------------------------
Select:
Var XXX = $("#ID option:selected").val();
= = = = = =
Two points to note:
1. Select "seleted" instead of "checked."
2. The default of select is "single", if it is multiple, I have not tried. I think we can handle each().