//全选表单代码不全,仅关键信息
<table
cellpadding
=
"3"
class
=
"data-grid"
>
<
thead
>
<
tr
>
<
th
><
input
type
=
"checkbox"
id
=
"checkAll"
name
=
"checkAll"
/></
th
>
<tbody>
<%
if
(listCRExtendMsg !=
null
&& listCRExtendMsg.size() > 0) {
%>
<%
int
index = 0;
for
(CRExtendMsg data : listCRExtendMsg) {
%>
<
tr
>
<
td
><
input
type
=
"checkbox"
name
=
"checkItem"
value
=
"
<%=
data.getId()
%>
"
/></
td
>
//js代码
//勾选复选框
$(
function
(){
var
$thr = $(
'table thead tr'
);
//这是获取表头的复选框
var
$tbr = $(
'tbody tr td'
);
var
$checkAll = $thr.find(
'input'
);
$checkAll.click(
function
(event){
/*将所有行的选中状态设成全选框的选中状态*/
$tbr.find(
'input'
).prop(
'checked'
,$(
this
).prop(
'checked'
));
/*阻止向上冒泡,以防再次触发点击操作*/
event.stopPropagation();
});
});
//前台勾选数据后的触发按钮
function
batchCloseList() {
var
nodes = $(
'tbody tr td input:checked'
);
//获取所有复选框选中的项作为一个对象
var
ids =
new
Array();
//创建一个接收id的数组
$.each(nodes,
function
(i){
//遍历所选的对象
if
($(nodes[i]).val() !=
'on'
) { //'on'是表头数据也就是全选的复选框
ids.push($(nodes[i]).val());
//将每一个选中对象的值赋给接收id的数组
}
});
if
(ids.length !=0) {
if
(confirm(
"是否将 "
+ ids.length +
" 条数据关闭推广?"
)){
var
param = {selectedItem : ids};
$.post(
'
<%=
path
%>
/chatRoom/closeExtend.htm
', param, function(data){
if
(data.code == 0) {
window.location.reload();
}
else
{
layer.alert(data.msg);
}
},
'json'
);
}
}
}
//前台传值为数组,后台转为list接收
@ResponseBody
@RequestMapping
(value =
"
/closeExtend
"
)
public
Map<String, Object> closeExtend(
@RequestParam(value = "selectedItem[]", required = false
) List<String> selectedItem, HttpServletRequest request, ModelMap model) {
Map<String, Object> data = Constants.
newReturnMap
(0);
String isOpenExtend =
"0"
;
Boolean success =
chatRoomService
.closeExtend(selectedItem, isOpenExtend);
if
(!success) {
data.put(
"code"
, -1);
data.put(
"msg"
,
"修改失败!"
);
}
return
data;
}