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

How to get multiple values ​​selected in checkbox in js

一个新手
Release: 2017-09-30 09:40:30
Original
3014 people have browsed it

Idea: Use the name attribute value to obtain the checkbox object, and then loop to determine the checked attribute (true means selected, false means unchecked). Here is an example demonstration:

1, HTML structure




    1



    2



    3



    4



    5

Copy after login

2, javascript code (jQuery)


function show(){
    obj = document.getElementsByName("test");
    check_val = [];
    for(k in obj){
        if(obj[k].checked)
            check_val.push(obj[k].value);
    }
    alert(check_val);
}
Copy after login

3. Demonstration effect

The above is the detailed content of How to get multiple values ​​selected in checkbox in js. For more information, please follow other related articles on the PHP Chinese website!

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!