1、復(fù)選框的取值:(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" >支付寶在線繳費(fèi) </ label > < label class = "checkbox-inline" > < input type = "checkbox" name = "payoperator" value = "2" checked = "checked" >支付寶代扣繳費(fèi) </ label > < label class = "checkbox-inline" > < input type = "checkbox" name = "payoperator" value = "3" checked = "checked" >支付寶當(dāng)面付 </ label > </ div > </ div > |
復(fù)選框中name="payoperator"必須相同,復(fù)選框才會(huì)生效
2、復(fù)選框的賦值:
從后臺(tái)取到值后要先在前端頁(yè)面初始化(復(fù)選框都未選中)
$(“input[name=payoperator]”).attr(“checked”,false);
1
2
3
4
5
|
var detail = detaildata.pay_operator;(detaildata為從后臺(tái)取到的所有數(shù)據(jù)的值,pay_operator為數(shù)據(jù)庫(kù)的字段) var split = detail.split( "," ); for ( var i = 0; i < split.length; i++) { $( "input[name=payoperator][value=" +split[i]+ "]" ).attr( "checked" , "checked" ); } |
頁(yè)面布局與上方的布局取值一樣。
總結(jié)
到此這篇關(guān)于js中復(fù)選框的取值及賦值的文章就介紹到這了,更多相關(guān)js復(fù)選框的取值及賦值內(nèi)容請(qǐng)搜索服務(wù)器之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持服務(wù)器之家!
原文鏈接:https://blog.csdn.net/qq_42972375/article/details/109108583