addRadio("name值", "标题", "提示", "数据项", "默认值" [, "属性", "额外属性", "额外css类"])
标识符:radio
单选的用法和复选类似,请参照复选的用法。
参数含义类型namename值string
title标题string
tips提示string
options数据项array
default默认值string
attr属性array
extra_attr额外属性string
extra_class额外css类string
一个简单的单选
return ZBuilder::make("form")
->setPageTitle("添加")
->addRadio("city", "选择城市", "", ["gz" => "广州", "sz" => "深圳", "sh" => "上海"])
->fetch();
带默认值
return ZBuilder::make("form")
->addRadio("city", "选择城市", "", ["gz" => "广州", "sz" => "深圳", "sh" => "上海"], "gz")
->fetch();
定义属性
可以设置颜色、尺寸
颜色(color)
primary (默认)
default
info
success
warning
danger$list_city = ["gz" => "广州", "sz" => "深圳", "sh" => "上海"];
return ZBuilder::make("form")
->addRadio("city", "选择城市", "请选择城市", $list_city, "", ["color" => "danger"])
->fetch();
尺寸(size)
sm (默认)
nm
lg$list_city = ["gz" => "广州", "sz" => "深圳", "sh" => "上海"];
return ZBuilder::make("form")
->addRadio("city", "选择城市", "", $list_city, "", ["size" => "lg"])
->fetch();
两种属性一起使用
$list_city = ["gz" => "广州", "sz" => "深圳", "sh" => "上海"];
return ZBuilder::make("form")
->addRadio("city", "选择城市", "", $list_city, "", ["color" => "danger", "size" => "lg"])
->fetch();
添加额外属性
比如默认为禁用状态
$list_city = ["gz" => "广州", "sz" => "深圳", "sh" => "上海"];
return ZBuilder::make("form")
->setPageTitle("添加")
->addRadio("city", "选择城市", "", $list_city, "", "", "disabled")
->fetch();
添加额外css类
$list_city = ["gz" => "广州", "sz" => "深圳", "sh" => "上海"];
return ZBuilder::make("form")
->setPageTitle("添加")
->addRadio("city", "选择城市", "", $list_city, "", "", "", "active")
->fetch();
这里添加的css类是自定义的,有特殊要求时才需要,请根据实际开发来决定