; (function ($) {
//默认参数
var defaluts = {
select: "select",
select_text: "select_text",
select_ul: "select_ul"
};
$.fn.extend({
"select": function (options) {
var opts = $.extend({}, defaluts, options);
return this.each(function () {
var $this = $(this);
//console.log('----', $(this).attr("data-id"))
var data_id = $(this).attr("data-id")
//模拟下拉列表
if ($this.data("value") !== undefined && $this.data("value") !== '') {
$this.val($this.data("value"));
}
var _html = [];
_html.push("
");
_html.push("
" + $this.find(":selected").text() + "
");
_html.push("
");
$this.children("option").each(function () {
var option = $(this);
if ($this.data("value") == option.val()) {
_html.push("- " + option.text() + "
");
} else {
_html.push("- " + option.text() + "
");
}
});
_html.push("
");
_html.push("
");
var select = $(_html.join(""));
var select_text = select.find("." + opts.select_text);
var select_ul = select.find("." + opts.select_ul);
$this.after(select);
$this.hide();
//下拉列表操作
select.click(function (event) {
//关闭其他的下拉列表
$('.select_ul').slideup();
$(this).find("." + opts.select_ul).toggle().end().siblings("div." + opts.select).find("." + opts.select_ul).slideup();
event.stoppropagation();
//获取当前下拉列表的data-id
var data_id = $(this).attr('data-id');
//console.log(data_id);
var n = 0;
switch (data_id) {
case 'select1':
// 查找label_box下的.cur数量
// console.log($('.label_cont .label_box')[0].getelementsbyclassname('im'));
var n = $('.label_cont .label_box')[0].getelementsbyclassname('im').length;
break;
case 'select2':
// console.log($('.label_cont .label_box')[1]);
// console.log($('.label_cont .label_box')[1].getelementsbyclassname('im'));
var n = $('.label_cont .label_box')[1].getelementsbyclassname('im').length;
break;
case 'select3':
$('.label_cont .label_box')[2].getelementsbyclassname('im')
var n = $('.label_cont .label_box')[2].getelementsbyclassname('im').length;
break;
default:
break;
}
let num = n * 36
// console.log(num);
//$(".select_ul").css('top', '-' + num + 'px')
});
$("body").click(function () {
select_ul.slideup();
});
select_ul.on("click", "li", function () {
var li = $(this);
var val = li.addclass("cur").siblings("li").removeclass("cur").end().data("value").tostring();
if (val != 0) {
window.open(val);
// select_text.text(li.text());
// $this.val(val);
// $this.attr("data-value", val);
}
});
});
}
});
})(jquery);