多选框定义
多选框的出现时将商品循环多次出现,这里用到了el表达式和jstl标签库的foreEach标签,注意input框加上class属性,并加上存有id的属性value:
<c:forEach items="${productList}" var="product" varStatus="vs">
<input type="checkbox" class="check_pid" name="pid" value="${product.pid }">
</c:forEach>
获取选中的多选框
- 通过类选择器获得选中多选框对应的dom对象
- 获得到每个多选框的id
- 将获得的ID作为参数传递
function deleteSelectProduct(){
if(confirm("您确定删除选中商品吗?")){
var checkObject = [];
for(var i=0;i<$(".check_pid").length;i++){
if($(".check_pid")[i].checked){
checkObject.push($(".check_pid")[i]);
}
}
var pid = "" ;
for(var i=0;i<checkObject.length;i++){
pid += checkObject[i].getAttribute("value")+",";
}
console.log(pid);
window.location.href = "${pageContext.request.contextPath}/deleteSelectProduct?pid="+ pid;
}
}