Appearance
复选框
复选框控件用于在一组选项中选择多个值。
属性
sg-caption
- 说明:控件前面的文字
- 类型:
string
示例
json
"sg-caption":"请选择:"sg-captionclass
- 说明:控件前面的文字的样式,w1-w7 文字宽度 1-7 个字符,more 省略掉超过的字符(写法:w5 more)
- 类型:
string
示例
json
"sg-captionclass":"w5"sg-label
- 说明:checkbox 的文字
- 类型:
string
示例
json
"sg-label":"复选"value
- 说明:checkbox 的值
- 类型:
string
示例
json
"value":"1"方法
getCheckBoxValList
获取 checkbox 选中值,返回数组格式。
语法
js
getCheckBoxValList(name)参数
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| name | string | 是 | checkbox 控件的 name |
返回值
Array - 选中的 checkbox 值列表。
示例
js
// 获取 name 为 hobbies 的复选框选中值列表
var hobbies = getCheckBoxValList("hobbies");
console.log("选中的爱好: " + hobbies.join(", "));getCheckBoxValStr
获取 checkbox 选中值,返回字符串格式。
语法
js
getCheckBoxValStr(name, separator)参数
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| name | string | 是 | checkbox 控件的 name |
| separator | string | 是 | 分隔符 |
返回值
string - 使用指定分隔符连接的选中值字符串。
示例
js
// 获取 name 为 hobbies 的复选框选中值,用逗号分隔
var hobbies = getCheckBoxValStr("hobbies", ",");
console.log("选中的爱好: " + hobbies);setCheckBoxVal
以数组形式为 checkbox 赋值。
语法
js
setCheckBoxVal(name, list)参数
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| name | string | 是 | checkbox 控件的 name |
| list | Array | 是 | 值列表 |
示例
js
// 设置 name 为 hobbies 的复选框选中值
setCheckBoxVal("hobbies", ["reading", "music", "sports"]);setCheckBoxValStr
以字符串形式为 checkbox 赋值。
语法
js
setCheckBoxValStr(name, str, separator)参数
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| name | string | 是 | checkbox 控件的 name |
| str | string | 是 | 值字符串 |
| separator | string | 是 | 分隔符 |
示例
js
// 设置 name 为 hobbies 的复选框选中值,值为逗号分隔的字符串
setCheckBoxValStr("hobbies", "reading,music,sports", ",");setCheckChecked
设置单个 checkbox 的勾选状态。
语法
js
setCheckChecked(selector, status)参数
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| selector | string | 是 | 选择器(如 "#id" 或 ".class") |
| status | boolean | 是 | 状态(true 勾选 / false 取消勾选) |
示例
js
// 勾选 id 为 agree 的复选框
setCheckChecked("#agree", true);
// 取消勾选 class 为 terms 的复选框
setCheckChecked(".terms", false);getCheckChecked
判断单个 checkbox 是否勾选。
语法
js
getCheckChecked(selector, mode)参数
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| selector | string | 是 | 选择器(如 "#id" 或 ".class") |
| mode | string | 是 | 模式 |
返回值
boolean - true 表示勾选,false 表示未勾选。
示例
js
// 检查 id 为 agree 的复选框是否勾选
var isChecked = getCheckChecked("#agree", "normal");
if (isChecked) {
console.log("用户已同意条款");
} else {
console.log("用户未同意条款");
}