EasyUI/TopJUI之如何动态改变下拉列表框ComboBox输入框的背景颜色

简单记录一下html

前段时间接到客户需求:动态改变下拉列表框ComboBox输入框的背景颜色。前端

刚开始想的很简单在用户选择列表项的时候,判断一下列表框的value值添加相应的背景颜色就OK了,然而在实际操做的时候发现,怎么操做都没有效果,后来检查了一下html结构才知道原来操做的不是显示在页面上的元素,害我浪费了一些时间。前端框架

具体代码以下:框架

第一种:HTML

ui

<div class="topjui-col-sm6">
     <label class="topjui-form-label">性别</label>
     <div class="topjui-input-block">
         <input type="text" name="sex"
             data-toggle="topjui-combobox"
             data-options="data:[{value:1,text:'男'},{value:2,text:'女'}],
             onSelect: function(rec){  //在用户选择列表项的时候触发
                if(rec.value=='男'){
                    this.nextSibling.children[1].style.background='#00FF00'
                 }
                 else{
                      this.nextSibling.children[1].style.background='#FFFF00'
                 }
             }">
     </div>
</div>

  

第二种:jsthis

 

<input type="text" name="sex"
   data-toggle="topjui-combobox"
   data-options="data:[{value:1,text:'男'},{value:2,text:'女'}],
   onSelect: onSelect">
 
 
 
<script>
   function onSelect(rec){
       if(rec.value=='1'){
           this.nextSibling.children[1].style.background='#00FF00'
       }
       else{
           this.nextSibling.children[1].style.background='#FFFF00'
       }
   }
</script>

 

  

       我是根据用户选择列表项的value值进行判断,固然也能够根据text值进行判断,具体操做根据实际需求来,是否是特别简单呢。spa

      上面两种方式显示效果都同样,具体以下:code

        效果展现orm

         

 

总结:了解topjui组件的内部结构,对症下药。htm

       EasyUI中文网:http://www.jeasyui.cn

           TopJUI前端框架:http://www.topjui.com

           TopJUI交流社区:http://ask.topjui.com

 

原文出处:https://www.cnblogs.com/xvpindex/p/10907419.html

相关文章
相关标签/搜索