【杂谈】jquery怎样猎取复选框选中的值
2019-11-18杂谈搜奇网31°c
A+ A-
本篇文章重要给人人引见
jquery猎取复选框选中的值的完成要领。
在前面的文章中,我们已为人人引见过用js完成猎取复选框选中的值,其完成思绪并非很难,想必人人都有肯定的了解了。那末经由过程jquery猎取复选框选中的值,比js的要领更加轻便。
下面我们就经由过程细致的代码示例为人人细致引见jquery猎取复选框选中的值的完成要领。
代码以下:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <input type="checkbox" name="test" value="0"/>0 <input type="checkbox" name="test" value="1"/>1 <input type="checkbox" name="test" value="2"/>2 <input type="checkbox" name="test" value="3"/>3 <input type="checkbox" name="test" value="4"/>4 <input type="checkbox" name="test" value="5"/>5 <input type="checkbox" name="test" value="6"/>6 <input type="checkbox" name="test" value="7"/>7 <input type="button" onclick="jqchk()" value="提 交"/> </body> <script src="./js/jquery-1.4.4.min.js"></script> <script> function jqchk(){ //jquery猎取复选框值 var chk_value =[]; $('input[name="test"]:checked').each(function(){ chk_value.push($(this).val()); }); alert(chk_value.length==0 ?'你还没有挑选任何内容!':chk_value); } </script> </html>
完成效果以下图:
如图,当我们选中多个选项并提交时,经由过程弹窗提醒能够晓得,我们胜利猎取到了复选框选中的值。
那末jQuery猎取复选框选中的值的完成思绪,也是异常简朴的,重要就是经由过程each遍历出被选中的值。
本篇文章就是关于jQuery猎取复选框选中的值的要领引见,浅显易懂,具有肯定的参考价值,愿望对须要的朋侪有肯定的协助!
以上就是jquery怎样猎取复选框选中的值的细致内容,更多请关注ki4网别的相干文章!