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
|
/****處理checkbox 配合jquery,layer 使用****/
var
handleCheckbox;
function
HandleCheckbox(className) {
this
.className = className;
};
//全選
HandleCheckbox.prototype.Select =
function
() {
$(
"[class='"
+
this
.className +
"']:checkbox"
).prop(
"checked"
,
true
);
};
//取消全選
HandleCheckbox.prototype.unSelect =
function
() {
$(
"[class='"
+
this
.className +
"']:checkbox"
).removeAttr(
"checked"
);
};
//獲取 checkbox 實例
HandleCheckbox.prototype.GetInstance =
function
() {
var
Instances = $(
"[class='"
+
this
.className +
"']:checkbox:checked"
);
if
(Instances.length > 0) {
//console.log($(Instances[0]).attr("extend"));
return
Instances[0];
}
else
{
layer.msg(
'沒有選擇數據'
);
}
};
//獲取選中的值
HandleCheckbox.prototype.GetValues =
function
() {
var
result =
new
Array();
$(
"[class='"
+
this
.className +
"']:checkbox"
).each(
function
() {
if
($(
this
).is(
":checked"
)) {
result.push($(
this
).attr(
"value"
));
}
});
console.log(result);
return
result.join(
","
);
};
//檢查是否選中數據
HandleCheckbox.prototype.GetSingleValue =
function
() {
var
args =
this
.GetValues().split(
","
);
if
(args ==
""
|| args.length == 0) {
layer.msg(
'沒有選擇數據'
);
return
false
;
}
if
(args.length > 1) {
layer.msg(
'請選擇一條數據進行操做'
);
return
false
;
}
return
args[0];
};
(
function
() {
handleCheckbox =
new
HandleCheckbox(
"zz"
);
})();
---------調用示例---------
<a href=
"#"
onclick=
"handleCheckbox.Select();"
>全選</a>
|