JQuery obtains the selected checkbox value.
JQuery obtains the selected checkbox value.
1. Problem background
There are several multiple selection boxes. select several of them to obtain the selected values.
2. Design source code
<Meta content = "text/html; charset = UTF-8 "http-equiv =" Content-Type "/> <title> </title> <script type =" text/javascript "src =" jquery-2.2.0.js "> </script> <script type = "text/javascript"> $ (function () {$ ("input [name = 'ckb']: checkbox "). click (function () {var str = ""; $ ("input [name = 'ckb']: checkbox "). each (function () {if ($ (this ). is (": checked") {str + = $ (this ). attr ("value") + "," ;}}); if (str! = Null & str. length> 1) {str = str. substring (0, str. length-1) ;}alert (str );});}); </script> <input name = "ckb" type = "checkbox" value = "1"/> Apple <input name = "ckb" type = "checkbox" value = "2 "/> orange <input name =" ckb "type =" checkbox "value =" 3 "/> pear <input name =" ckb "type =" checkbox "value =" 4 "/> bananas3. Design Results