JQuery gets the selected value of radio:
<input type="radio" name="rd" id="rd1" value="1">1
<input type="radio" name="rd" id="rd2" value="2">2
<input type="radio" name="rd" id="rd3" value="3">3
All three methods are OK
$('input:radio:checked').val();
$("input[type='radio']:checked").val();
$("input[name='rd']:checked").val();
JQuery gets the selected value of select
<select name="products" id="sel">
<option value='1'>option1</option>
<option value='2' selected>option2</option>
<option value='3'>option3</option>
<option value='4'>option4</option>
</select>
Get the value of the selected item:
$('select#sel option:selected').val();
or
$('select#sel').find('option:selected').val();
Get the text value of the selected item:
$('select#seloption:selected').text();
or
$('select#sel').find('option:selected').text();
Get the index value of the currently selected item:
$('select#sel').get(0).selectedIndex;
JQuery gets the selected value of the check box:
<input type="checkbox" name="ck" value="checkbox1">checkbox1
<input type="checkbox" name="ck" value="checkbox2" checked>checkbox2
<input type="checkbox" name="ck" value="checkbox3">checkbox3
Get a single check box selected item:
$("input:checkbox:checked").val()
or
$("input:[type='checkbox']:checked").val();
or
$("input:[name='ck']:checked").val();
Get multiple check box items:
$('input:checkbox').each(function() {
if ($(this).attr('checked') ==true) {
alert($(this).val());
}
});
Read More:
- mysql workbench Error Code: 1046. No database selected Select the default DB to be used
- Django + jQuery get data in the form + Ajax send data
- When using freemaker template to get values, an error is reported when the attribute is empty
- JQ adds a click event to the option of select
- How to handle when select single is not allowed in loop
- Android:More than one file was found with OS independent path ‘res/values/values.xml
- JQuery determines whether a property has hasattr
- How to Use Apt get Command Under Mac OSX
- After BS4, select was used to locate
- Error reporting under layui dynamic select IE
- Error reported by nodejs server of CentOS system: solution to cannot find module ‘jQuery’
- How to get all the keys of map by golang
- How to use C # to get image format without system. Drawing. Common
- Solution to report undefined a error when using jquery
- there was an error running the selected code generator unable to retrieve metadata for
- [windows] U disk installed system, unable to format the selected partition [error: 0x8004242d]
- How to select the jar package version for Maven package when the jar package versions referenced by multiple modules are inconsistent
- about jQuery.js The solution to always reporting errors
- Uncaught Error: Call to undefined function mysql_select_db()
- ValueError: too many values to unpack