easyui 选择框(ComboBox)选中时触发事件

来源:互联网 发布:彩票预测app源码 编辑:程序博客网 时间:2024/04/28 00:31

easyui 选择框默认屏蔽了onChange()事件,在使用时可以使用自带的onSelect事件

//选择后触发事件,
$(function(){
$("#groupCombobox").combobox({
onSelect:function(record){
var curValue=$('#groupCombobox').combobox('getValue');
if(curValue==1){
$("[name='userGroupRight']").attr("checked",'true');
}else if(curValue==2){
$("[name='userGroupRight']").removeAttr("checked");
$("[name='userGroupRight']").each(function(){
if($(this).val()==1){
$(this).attr("checked",'true');
}
if($(this).val()==3){
$(this).attr("checked",'true');
}
if($(this).val()==5){
$(this).attr("checked",'true');
}
})
}else{
$("[name='userGroupRight']").removeAttr("checked");
}
}
});
});


注:一般在页面弹出新增窗口时,有下拉选择框,此激活代码应与dialog放在一块才能激活。

<div id="groupForm" class="easyui-dialog" style="width:425px;height:350px;" closed="true" buttons="#dlg-buttons" data-options="modal:true">
    <div class="easyui-panel" style="width:410px">
       <div style="padding:10px 60px 20px 60px">
       <form id="userGroupForm" method="post">
           <table cellpadding="5">
               <tr>
                   <td>名称:</td>
                   <td><input class="easyui-validatebox textbox" type="text" name="name" id="name" data-options="required:true"></input></td>
               </tr>
               <tr>
                   <td>说明:</td>
                   <td><input class="easyui-validatebox textbox" type="text" id="description" name="description"></input></td>
               </tr>
               <tr>
                   <td>用户权限:</td>
                   <td>
                   <select id="groupCombobox" name="groupCombobox" class="easyui-combobox" style="width:200px;" data-options="required:true">
    <option value="1" selected="selected">系统管理员</option>
   <option value="2">普通用户</option>
   <option value="3">自定义权限</option>
</select>
                   </td>
               </tr>
               <tr>
                   <td></td>
                   <td>
                   <input type="checkbox" value="1" checked name="userGroupRight">查询本人导入的检查记录</input><br>
                   <input type="checkbox" value="2" checked name="userGroupRight">查询所有检查记录</input><br>
                   <input type="checkbox" value="3" checked name="userGroupRight">查询本人的操作日志</input><br>
                   <input type="checkbox" value="4" checked name="userGroupRight">查询所有操作日志</input><br>
                   <input type="checkbox" value="5" checked name="userGroupRight">修改用户密码</input><br>
                   <input type="checkbox" value="6" checked name="userGroupRight">管理用户</input>
                   </td>
               </tr>
           </table>
       </form>
       <div style="text-align:center;padding:5px">
           <a href="javascript:void(0)" class="easyui-linkbutton" onclick="userGroupsubmitForm()">提交</a>
           <a href="javascript:void(0)" class="easyui-linkbutton" onclick="userGroupclearForm()">取消</a>
       </div>
   </div>
   </div>
   <script>
       function userGroupsubmitForm(){
           $('#userGroupForm').form('submit', {
   url:'groupController.do?addgroup',
   onSubmit: function(){
    return $(this).form('validate');
   }
}); 
/* $('#groupForm').dialog('close');
$('#userTreegrid').treegrid('reload'); */
       }
       function userGroupclearForm(){
           $('#groupForm').dialog('close');
       }
       
       //选择后触发事件
       $(function(){
        $("#groupCombobox").combobox({
onSelect:function(record){
var curValue=$('#groupCombobox').combobox('getValue');
if(curValue==1){
$("[name='userGroupRight']").attr("checked",'true');
}else if(curValue==2){
$("[name='userGroupRight']").removeAttr("checked");
$("[name='userGroupRight']").each(function(){
if($(this).val()==1){
$(this).attr("checked",'true');
}
if($(this).val()==3){
$(this).attr("checked",'true');
}
if($(this).val()==5){
$(this).attr("checked",'true');
}
})
}else{
$("[name='userGroupRight']").removeAttr("checked");
}
}
});
       });
   </script>
  </div>

0 0
原创粉丝点击