layui 动态设置checbox 选中状态的例子
作者:blowDestiny 时间:2024-04-18 09:28:05
最近在使用layui前端框架,在使用单选按钮、下拉菜单select、checkbox等控件的时候 往往遇到一些初始化的东西。
有时候会发现,自己动态append进去的代码要不就是没有显示,要不就是初始化默认选中出问题。
以上这些情况进行了测试:
第一种情况:动态append()html代码后没有显示空间的解决方案:
添加
layui.form.render();//重新渲染 可以解决多种没有显示的情况
第二种情况:动态设置默认选中状态没有效果解决方案:
细分为两种情况:
(1)在html页面代码下(没有在layer初始化框架中,即没有在layui.use([], function(){ }) 中进行初始化)
以初始化checkbox默认选中为例:
$('.xxx').attr("checked", true); //注意这里使用的是attr()
layui.form.render(); //重新渲染显示效果
(2)在layui.use(); 初始化中初始化一般这种情况会出现在调用api接口错误之后使用不然checkbox改变状态
layui.use(['form','layer'],function(){
var form = layui.form
layer = parent.layer === undefined ? layui.layer : top.layer,
$ = layui.jquery;
if ($('.xxxx').attr("checked") === "checked") { //判断是否选中
$('.xxxx').prop("checked", true); //设置选中 注意这里使用的是prop(), 这里要是使用了attr()是无效的
} else {
$('.xxxx').prop("checked", false);
}
form.render(); //重新渲染
});
来源:https://blog.csdn.net/InnovationAD/article/details/80495044
标签:layui,checbox
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Windows下Eclipse+PyDev配置Python+PyQt4开发环境
2021-01-26 20:13:42
![](https://img.aspxhome.com/file/2023/3/97693_0s.png)
pandas 选择某几列的方法
2022-04-08 13:14:36
python标准算法实现数组全排列的方法
2022-03-18 15:11:38
解决python 3 urllib 没有 urlencode 属性的问题
2022-03-31 12:42:44
python实现DEM数据的阴影生成的方法
2023-11-09 11:17:25
![](https://img.aspxhome.com/file/2023/4/135204_0s.png)
OAuth 2.0 概念及授权流程梳理
2023-06-28 02:41:28
![](https://img.aspxhome.com/file/2023/0/131810_0s.jpg)
python中flatten()参数示例详解
2022-07-03 11:19:57
![](https://img.aspxhome.com/file/2023/5/130575_0s.png)
从算法入手讲解SQL Server的典型示例
2008-12-18 14:51:00
sqlserver 脚本和批处理指令小结
2024-01-20 06:41:37
约瑟夫问题的Python和C++求解方法
2023-12-05 15:09:28
PyQt5 PySide2 触摸测试功能的实现代码
2022-06-23 22:22:25
![](https://img.aspxhome.com/file/2023/3/86643_0s.png)
go语言睡眠排序算法实例分析
2023-07-15 17:42:56
Python实现使用request模块下载图片demo示例
2021-10-08 10:13:48
![](https://img.aspxhome.com/file/2023/7/90627_0s.png)
分享18个最佳代码编辑器/IDE开发工具
2022-03-26 01:31:24
![](https://img.aspxhome.com/file/2023/7/81587_0s.png)
详解Python字符串切片
2021-09-10 05:10:43
![](https://img.aspxhome.com/file/2023/5/67425_0s.png)
Python免登录实现域名解析的示例详解
2022-12-17 21:26:50
![](https://img.aspxhome.com/file/2023/2/127702_0s.png)
PHP Web木马扫描器代码 v1.0 安全测试工具
2024-04-29 13:58:09
JavaScript中的Promise使用详解
2024-04-18 10:53:52
![](https://img.aspxhome.com/file/2023/9/136329_0s.jpg)
详解Python3中字符串中的数字提取方法
2021-02-22 06:08:15
Pycharm搭建一个Django项目的方法步骤
2022-04-12 12:46:41
![](https://img.aspxhome.com/file/2023/1/81491_0s.jpg)