1、复选框的取值:(js部分)
1
2
3
|
var checkboxdata = $(“input[name=payoperator]:checked”).map( function () { return $( this ).val(); }).get().join( "," ); |
1
2
3
4
5
6
7
8
9
10
11
|
< div class = "form-group" > < label class = "col-lg-2 col-md-2 col-sm-12 control-label" >支付方式</ label > < div class = "col-lg-4 col-md-4" > < label class = "checkbox-inline" > < input type = "checkbox" name = "payoperator" value = "1" >支付宝在线缴费 </ label > < label class = "checkbox-inline" > < input type = "checkbox" name = "payoperator" value = "2" checked = "checked" >支付宝代扣缴费 </ label > < label class = "checkbox-inline" > < input type = "checkbox" name = "payoperator" value = "3" checked = "checked" >支付宝当面付 </ label > </ div > </ div > |
复选框中name="payoperator"必须相同,复选框才会生效
2、复选框的赋值:
从后台取到值后要先在前端页面初始化(复选框都未选中)
$(“input[name=payoperator]”).attr(“checked”,false);
1
2
3
4
5
|
var detail = detaildata.pay_operator;(detaildata为从后台取到的所有数据的值,pay_operator为数据库的字段) var split = detail.split( "," ); for ( var i = 0; i < split.length; i++) { $( "input[name=payoperator][value=" +split[i]+ "]" ).attr( "checked" , "checked" ); } |
页面布局与上方的布局取值一样。
总结
到此这篇关于js中复选框的取值及赋值的文章就介绍到这了,更多相关js复选框的取值及赋值内容请搜索服务器之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持服务器之家!
原文链接:https://blog.csdn.net/qq_42972375/article/details/109108583