Home >Web Front-end >JS Tutorial >How to select multiple values in checkbox in js?
The content of this article is about how to select multiple values in the checkbox in js? It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
<input type="checkbox" name="test" value="1"/><span>1</span> <input type="checkbox" name="test" value="2"/><span>2</span> <input type="checkbox" name="test" value="3"/><span>3</span> <input type="checkbox" name="test" value="4"/><span>4</span> <input type="checkbox" name="test" value="5"/><span>5</span> <input type='button' value='提交' onclick="show()"/>
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); }
Related recommendations:
What is implicit type conversion? Introduction to js implicit type conversion
#What is the concept of js execution mechanism? Implementation method of js execution mechanism
The above is the detailed content of How to select multiple values in checkbox in js?. For more information, please follow other related articles on the PHP Chinese website!