首页 > 代码库 > combox用法

combox用法

html

<form id="myForm" > <input id="cc" value=http://www.mamicode.com/"001" style="width: 50px;"> <select class="easyui-combobox" name="sex0" id="sex0" data-options="width:100,panelHeight:72,editable:false,required:true,validType:‘comboxRequired[\‘-- 请选择 --\‘]‘"> <option value=http://www.mamicode.com/"">-- 请选择 --</option> <option value=http://www.mamicode.com/"男">男</option> <option value=http://www.mamicode.com/"女">女</option> </select> <select class="easyui-combobox" name="sex1" id="sex1" data-options="width:100,panelHeight:72,editable:false,required:true"> <option value=http://www.mamicode.com/"男">男</option> <option value=http://www.mamicode.com/"女">女</option> </select> <button type="button" id="formresetButton">reset<button> <button type="button" id="formSubmitButton">submit<button> </form>

js
//添加一个验证类型
$.extend($.fn.validatebox.defaults.rules, {
    comboxRequired: {
        validator: function(value, param){
            return value!= param[0];
        },
        message: ‘必须选择一个‘
    }
});
$(‘#formresetButton‘).on("click",function(){
    $(‘#myForm‘).form("reset");
});
$(‘#formSubmitButton‘).on("click",function(){
    $(‘#myForm‘).form("submit",{
        onSubmit: function(){
            var isValid = $(this).form(‘validate‘);
            //如果验证失败,返回false,form不提交
            console.log(isValid);
            return isValid;
        }
    });

});

combox用法