网页资讯视频图片知道文库贴吧地图采购
进入贴吧全吧搜索

 
 
 
日一二三四五六
       
       
       
       
       
       

签到排名:今日本吧第个签到,

本吧因你更精彩,明天继续来努力!

本吧签到人数:0

一键签到
成为超级会员,使用一键签到
一键签到
本月漏签0次!
0
成为超级会员,赠送8张补签卡
如何使用?
点击日历上漏签日期,即可进行补签。
连续签到:天  累计签到:天
0
超级会员单次开通12个月以上,赠送连续签到卡3张
使用连续签到卡
01月22日漏签0天
jquery吧 关注:52,178贴子:156,688
  • 看贴

  • 图片

  • 吧主推荐

  • 游戏

  • 1回复贴,共1页
<<返回jquery吧
>0< 加载中...

新人请教,如何修改,才可以使两个对象不相互影响

  • 只看楼主
  • 收藏

  • 回复
  • c517718004
  • 初涉江湖
    1
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
(function($) {
var SelectChoice = {
set: function() {
SelectChoice.level = 1;
if (settings.sid != 0) {
SelectChoice.name = _this.nextAll('select').last().attr('name');
SelectChoice.status = true;
_this.change(function(event) {
SelectChoice.level = $(this).index() + 1;
SelectChoice.getdata($(this).val());
if ($(this).val() == 0) {
$(this).nextAll('select').remove();
} else {
SelectChoice.getdata($(this).val());
}
});
_this.nextAll('select').change(function(event) {
SelectChoice.level = $(this).index() + 1;
SelectChoice.getdata($(this).val());
});
} else {
SelectChoice.name = _this.attr('name');
SelectChoice.status = false;
SelectChoice.getdata(settings.pid);
}
},
view: function() {
if (settings.data == null || settings.data == '') {
} else {
if (SelectChoice.level == 1 && SelectChoice.status == false) {
_this.change(function(event) {
SelectChoice.level = $(this).index() + 1;
if ($(this).val() == 0) {
$(this).nextAll('select').remove();
} else {
SelectChoice.getdata($(this).val());
}
});
_this.append('<option value="0">请选择</option>');
$.each(settings.data, function(index, el) {
_this.append('<option value="' + el.id + '">' + el.name + '</option>');
});
SelectChoice.status = true;
} else {
var select = $('<select class="select"><option value="0">请选择</option></select>');
select.attr('name', SelectChoice.name);
select.change(function(event) {
SelectChoice.level = $(this).index() + 1;
SelectChoice.getdata($(this).val());
});
$.each(settings.data, function(index, el) {
select.append('<option value="' + el.id + '">' + el.name + '</option>');
});
var this_dom = null;
if (SelectChoice.level == 1) {
_this.removeAttr('name').nextAll('select').remove();
this_dom = _this;
} else {
this_dom = _this.nextAll('select:eq(' + (SelectChoice.level - 2) + ')');
this_dom.nextAll('select').remove();
_this.removeAttr('name').nextAll('select').removeAttr('name');
}
this_dom.after(select);
}
}
},
//获取数据
getdata: function(pid) {
if (settings.data_url == null || settings.data_url == '') {
} else {
if (SelectChoice.level < settings.level) {
$.ajax({
url: settings.data_url,
type: 'POST',
dataType: 'json',
data: {
pid: pid,
},
async: false,
})
.done(function(data) {
if (data.status) {
settings.data = data.data;
} else {
settings.data = null;
}
})
.fail(function() {
console.log("error");
})
.always(function() {
console.log("complete");
});
SelectChoice.view();
}
}
},
}
var methods = {
init: function(options) {
settings = $.extend({}, defaults, options);
return this.each(function() {
SelectChoice.set();
});
},
};
var defaults = {
sid: 0,
pid: 0,
level: 4,
data_url: null,
data: null,
};
var settings = {}; //将一个空对象做为第一个参数
var _this = null;
$.fn.selectchoice = function(method) {
_this = this;
if (methods[method]) {
return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
} else if (typeof method === 'object' || !method) {
return methods.init.apply(this, arguments);
} else {
$.error('Method ' + method + ' does not exist on jQuery.selectchoice');
}
};
})(jQuery);
/*********************************************************************************/
<script type="text/javascript">
jQuery(function($) {
var a = $('#abc').selectchoice({
'data_url':'<{:U("Area/getArea")}>',
});
var b= $('#abcd').selectchoice({
'data_url':'<{:U("Area/getArea")}>',
});
});
</script>
<select id="abc" name="abc"></select>
<select id="abcd" name="abc"></select>


  • c517718004
  • 初涉江湖
    1
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
没有人指点吗?


登录百度账号

扫二维码下载贴吧客户端

下载贴吧APP
看高清直播、视频!
  • 贴吧页面意见反馈
  • 违规贴吧举报反馈通道
  • 贴吧违规信息处理公示
  • 1回复贴,共1页
<<返回jquery吧
分享到:
©2026 Baidu贴吧协议|隐私政策|吧主制度|意见反馈|网络谣言警示