本文实例讲述了jQuery插件扩展的方法。分享给大家供大家参考,具体如下:
函数变量
}
function foo1(a,b,c) {
// I'm the callback
alert(a + " " + b + " " + c);
}
doSomething(foo1); // foo1函数将使用callback函数中的数据 stuff goes here
var foo2 = function(a,c) {
// I'm the callback
alert(a + " " + b + " " + c);
}
doSomething(foo2); // foo2函数将使用callback函数中的数据 stuff goes here
doSomething(function(a,c){
alert(a + " " + b + " " + c); // function函数将使用callback函数中的数据 stuff goes here
});
callback这个参数必须是函数才有效。才能起到回调的作用。
函数变量
}else{
alert('jb51.cc');
}
}
function foo1(a,c){
alert(a + " " + b + " " + c); // function函数将使用callback函数中的数据 stuff goes here
});
var foo3 = 'a';
doSomething(foo3);
foo3不是函数的时候,弹出jb51.cc
jQuery实例
原函数
添加回调
添加回调函数changeHandle
给回调函数赋值
函数
var prov_id = prov_obj.get(0).selectedIndex;
var city_id = city_obj.get(0).selectedIndex;
var dist_id = dist_obj.get(0).selectedIndex;
if(!settings.required){
prov_id--;
city_id--;
dist_id--;
};
if(dist_id<0){
var data = {
prov: city_json.citylist[prov_id].p,city: city_json.citylist[prov_id].c[city_id].n,dist: null
};
}else{
var data = {
prov: city_json.citylist[prov_id].p,dist: city_json.citylist[prov_id].c[city_id].a[dist_id].s
};
}
changeHandle(data,areaType); // 返回两个处理好的数据
}
};
获取省市县数据data以及触发的change事件类型areaType
在各个事件中执行
前端使用
使用回调回来的data数据,用于selectAgent函数中
'getagent'))}",data:"city="+city+"&district="+district,success:function(json){
json = JSON.parse(json);
opt_str = ""
if(json.status == 1){
$.each(json.data,function(index,con){
opt_str += "
去ajax获取相应的代理商数据。
改造插件完成。
更多关于jQuery相关内容感兴趣的读者可查看本站专题:《》、《》、《》、《》、《》、《》及《用法总结》
希望本文所述对大家jQuery程序设计有所帮助。