简单记录一下
前段时间接到客户需求:动态改变下拉列表框combobox输入框的背景颜色。
刚开始想的很简单在用户选择列表项的时候,判断一大运河申遗下列表框的value值添加相应的背景颜色就ok了,然而在实际操作的时候发现,怎么操作都没有效果,后来检查了一下html结构才狗头人身知道原来操作的不是显示在页面上的元素,害我浪费了一些时间。
具体代码如下:
第一种:html
<div class="topjui-col-sm6"> <label class="topjui-form-label">性别</label> <div class="topjui-input-block"> <input type="text" name="x" data-toggle="topjui-comb大专本科obox" data-options="data:[{value:1,text:'男'},{value:2,text:'女'}], onlect: function(rec){ //在用户选择列表项的时候触发 if(rec.value=='男'){ this.nextsibling.children[1].style.background='#00ff00' } el{ this.nextsibling.children[1].style.background='#ffff00' } }"> </div></div>
十里画廊
第二种:js
<input type="text" name="x" data-toggle="topjui-combobox" data-optio读书让生活更美好ns="data:[{value:1,text:'男'},{value:2,text:'女'}], onlect: onlect"> <script> function onlect(rec){ if(rec.value=='1'){ this.nextsibling.children[1].style.background='#00ff00' } el{ this.nextsibling.children[1].style.background='#ffff00' } }</script>
我是根据用户选择列表项的value值进行判断,当然也可以根据text值进行判断,具体操作根据实际需求来,是不是特别简单呢。
上面两种方式显示效果都一样,具体如下:
效果展示
总结:了解topjui组件的内部结构,对症下药。
topjui前端框架:
topjui交流社区:
本文发布于:2023-04-03 14:40:25,感谢您对本站的认可!
本文链接:https://www.wtabcd.cn/fanwen/zuowen/0453a0d9d97c496bf0b211abd4f9cc5d.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文word下载地址:基于EasyUI的TopJUI前端框架之如何动态改变下拉列表框ComboBox输入框的背景颜色.doc
本文 PDF 下载地址:基于EasyUI的TopJUI前端框架之如何动态改变下拉列表框ComboBox输入框的背景颜色.pdf
留言与评论(共有 0 条评论) |