首页 > 代码库 > easyui相关问题
easyui相关问题
1、解决easyui的输入框有些属性不起效果的问题
$(".easyui-combobox").each(function(i){
var span = $(this).siblings("span")[0];
var targetInput = $(span).find("input:first");
if(targetInput){
$(targetInput).attr("placeholder", $(this).attr("placeholder"));
}
});
2、按↓键时弹出下拉框
function showPanel(id){
$("input",$("#"+id).next("span")).keyup(function (e) {
if (e.keyCode == 40) {
$("#"+id).combobox("showPanel");
}
});
}
3、省市区三级联动,该方法适合选择省、市时触发
function load(param, success, error,url,parentCode,childCode){
var conditions = [];
var condition = {};
condition.fieldName=parentCode;
condition.operator=0;
condition.lowValue=http://www.mamicode.com/param;
conditions.push(condition);
var json = {"search_condition" : JSON.stringify(conditions) };
$.ajax({
url: url,
type: "POST",
data: json,
dataType: "json",
success: function(data) {
success(data);
showPanel(childCode)
comboInputPlaceholder();
},
//异常处理
error: function (xml, text, msg) {
error.apply(this, arguments);
}
});
}
function loadAddress(parentCode,childCode,childName,url){
$(‘#‘+parentCode).combobox({
onSelect: function(rec){
var prefix = parentCode.substring(0,parentCode.length-9);//前缀
var prov_code = parentCode.substring(parentCode.length-9,parentCode.length);//截取parentCode值,为后9个字符
var child_code = childCode.substring(childCode.length-9,childCode.length);//截取childCode值,为后9个字符
var child_name = childName.substring(childName.length-14,childName.length);//截取childName值,为后14个字符
if(prov_code == "prov_code"){
var para = rec.code_type;
if(para == undefined || para == "" || para == null){
para = rec[parentCode];
}
$(‘#‘+prefix+"area_code").combobox(‘setValue‘,‘‘);
$(‘#‘+prefix+"area_code").combobox({
valueField: ‘area_code‘,
textField: ‘area_code_name‘,
loader: function(param, success, error){
load(para, success, error,url,prov_code,childCode);
},
filter : function(q, row) {
var opts = $(this).combobox(‘options‘);
return row[opts.textField].indexOf(q) > -1;
},
loadFilter: function(data){
if (data!=null && data.errorCode>0){
if(data.msg!=null && data.msg!=""){
$$.showJcdfMessager(‘提示消息‘, data.msg, ‘warning‘);
}
}
return data.data;
}
});
$(‘#‘+childCode).combobox({
valueField: child_code,
textField: child_name,
loader: function(param, success, error){
load(para, success, error,url,prov_code,childCode);
},
filter : function(q, row) {
var opts = $(this).combobox(‘options‘);
return row[opts.textField].indexOf(q) > -1;
},
loadFilter: function(data){
if (data!=null && data.errorCode>0){
if(data.msg!=null && data.msg!=""){
$$.showJcdfMessager(‘提示消息‘, data.msg, ‘warning‘);
}
}
return data.data;
}
});
}else{
var para = rec[prov_code];
if(!para){
para = rec.code_type;
}
if(para == undefined || para == "" || para == null){
para = rec[prov_code];
}
$(‘#‘+childCode).combobox({
valueField: child_code,
textField: child_name,
loader: function(param, success, error){
load(para, success, error,url,prov_code,childCode);
},
filter : function(q, row) {
var opts = $(this).combobox(‘options‘);
return row[opts.textField].indexOf(q) > -1;
},
loadFilter: function(data){
if (data!=null && data.errorCode>0){
if(data.msg!=null && data.msg!=""){
$$.showJcdfMessager(‘提示消息‘, data.msg, ‘warning‘);
}
}
return data.data;
}
});
}
}
})
}
4、身份证验证
var aCity={11:"北京",12:"天津",13:"河北",14:"山西",15:"内蒙古",21:"辽宁",22:"吉林",23:"黑龙江",31:"上海",32:"江苏",33:"浙江",34:"安徽",35:"福建",36:"江西",37:"山东",41:"河南",42:"湖北",43:"湖南",44:"广东",45:"广西",46:"海南",50:"重庆",51:"四川",52:"贵州",53:"云南",54:"西藏",61:"陕西",62:"甘肃",63:"青海",64:"宁夏",65:"新疆",71:"台湾",81:"香港",82:"澳门",91:"国外"}
function isCardID(sId){
var iSum=0 ;
var info="";
if(!/^\d{17}(\d|x)$/i.test(sId))return false;
sId=sId.replace(/x$/i,"a");
if(aCity[parseInt(sId.substr(0,2))]==null) return false;
sBirthday=sId.substr(6,4)+"-"+Number(sId.substr(10,2))+"-"+Number(sId.substr(12,2));
var d=new Date(sBirthday.replace(/-/g,"/")) ;
if(sBirthday!=(d.getFullYear()+"-"+ (d.getMonth()+1) + "-" + d.getDate()))return false;
for(var i = 17;i>=0;i --) iSum += (Math.pow(2,i) % 11) * parseInt(sId.charAt(17 - i),11) ;
if(iSum%11!=1) return false;
return true;
}
$.extend($.fn.validatebox.defaults.rules, {
idcared: {
validator: function(value,param){
var flag= isCardID(value);
return flag==true?true:false;
},
message: ‘不是有效的身份证号码‘
},
5、下拉框默认选中第一条数据,调用该方法必须要有initControlSetting()方法,且写在其后
function comboboxFristData(id){
var jq_id = "#"+id;
var data = http://www.mamicode.com/$(jq_id).combobox(‘getData‘);
if (data.length > 0) {
$(jq_id).combobox(‘select‘, data[0].code_name);
}
}
6、当下拉框中的值为‘请输入‘,点击时清空
function clearcombo(param){
$(".combo").click(function(){
var text = $(‘#‘+param).combobox(‘getText‘);
if(text == "请输入")
$(this).prev().combobox("setValue","");
})
}
easyui相关问题