option_check_wev8.js
4.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/*****************************************
调用方法为:
Jselect($("#inputid"),{
bindid:'bindid',
hoverclass:'hoverclass',
optionsbind:function(){return hqhtml();}
});
inputid为下拉框要绑定的文本框id
bindid为点击弹出/收回下拉框的控件id
hoverclass为鼠标移到选项时的样式
hqhtml为绑定的数据
******************************************/
(function($) {
$.showselect = {
init: function(o, options) {
var defaults = {
bindid: null,
//事件绑定在bindid上
hoverclass: null,
//鼠标移到选项时样式名称
optionsbind: function() {}, //下拉框绑定函数
callback: function() {}
}
var options = $.extend(defaults, options);
if (options.optionsbind != null) { //如果绑定函数不为空
this._setbind(o, options);
}
if (options.bindid != null) {
this._showcontrol(o, options);
}
var selarray = new Array();
$(o).next().find("input[type=checkbox]").each(function() {
if ($(this).attr("checked")) selarray.push($(this).parent().next().text());
});
$(o).val(selarray.join(','));
},
_showcontrol: function(o, options) { //控制下拉框显示
$("#" + options.bindid).toggle(function() {
$(o).next().slideDown();
},
function() {
$(o).next().slideUp();
});
$(document.body).bind("click", function () {
$(o).next().slideUp();
});
},
_setbind: function(o, options) { //绑定数据
var optionshtml = "<div style=\"z-index: 999; position: absolute;\" class='selectInput'>" + options.optionsbind() + "</div>";
$(o).after(optionshtml);
var offset = $(o).offset();
var w = $(o).width();
var h = $(o).height();
if (offset.top == 0) {
var prvEle = $($(o).parent().parent().prev().children()[0]).children();
offset = prvEle.offset();
w = prvEle.width();
h = prvEle.height();
}
$(o).next().css({
top: offset.top + h,
left: offset.left,
width: w
});
if (options.hoverclass != null) {
$(o).next().find("tr").hover(function() {
$(this).addClass(options.hoverclass);
},
function() {
$(this).removeClass(options.hoverclass);
});
}
$(o).next().find("input[type=checkbox]").filter("[lang=checked]").each(function() {
$(this).attr("checked", "checked");
});
$(o).next().find("input[type=checkbox]").click(function(evt) {
var $ckoption = $(this).attr("checked");
if ($ckoption) {
$(this).attr("checked", "");
} else {
$(this).attr("checked", "checked");
}
});
$(o).next().find("tr").click(function(evt) {
try {
evt.stopPropagation();
} catch (e) {};
var $ckflag = $(this).find("input[type=checkbox]");
if ($ckflag.attr("checked")) {
$ckflag.attr("checked", "");
$ckflag.attr("lang", "");
} else {
$ckflag.attr("checked", "checked");
$ckflag.attr("lang", "checked");
}
var selarray = new Array();
$(o).next().find("input[type=checkbox]").each(function() {
if ($(this).attr("checked")) selarray.push($(this).parent().next().text());
});
$(o).val(selarray.join(','));
options.callback();
});
$(o).next().hide();
}
}
Jselect = function(o, json) {
$.showselect.init(o, json);
};
})(jQuery);
function getEvent() {
if (window.ActiveXObject) {
return window.event;// 如果是ie
}
func = getEvent.caller;
while (func != null) {
var arg0 = func.arguments[0];
if (arg0) {
if ((arg0.constructor == Event || arg0.constructor == MouseEvent)
|| (typeof (arg0) == "object" && arg0.preventDefault && arg0.stopPropagation)) {
return arg0;
}
}
func = func.caller;
}
return null;
}