Home > Web Front-end > JS Tutorial > body text

Example of jQuery obtaining input, checkbox, radio, and select based on ID_jquery

WBOY
Release: 2016-05-16 16:39:57
Original
1143 people have browsed it

input:

var xxx = $('#ID').val()

-------------------------------------------------- ----------------------------------

checkbox:

var xxx = [ ];
$('input[name=MyName]:checked).each(function(index, element) {
xxx.push($(element).val());
// 或者 xxx.push($(this).val());
});
Copy after login

Note: This is not based on ID, which is a bit loose. If your checkbox element is a child element of a container (assuming the container's id is con_id), you can choose like this:

======

$('#con_id input[name=MyName]:checked')
或者
$('input[name=MyName]:checked', '#con_id')
Copy after login

-------------------------------------------------- ----------------------------------

radio:

var xxx = $(''input[name=MyName]:checked”).val();

======

Note: Nothing based on ID here. To limit the specified ID, see the checkbox above

-------------------------------------------------- ----------------------------------

select:

var xxx = $("#ID option:selected").val();

======

Note two points:

1. The selected attribute of select is "seleted", not "checked".

2. Select is "single selection" by default. If it is multiple selection, I have not tried it. Presumably it can be handled with .each().

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!