对jquery内容很薄弱,只能网上找找源码,这个是我经过实践可以用的一个案例。然后改写了一下,把其相关信息传送到后台,然后再在后台进行相关操作。
<%@taglib uri="/struts-tags" prefix="s"%>
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<html>
<head>
<script src="http://code.jquery.com/jquery-1.4.4.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function() {
$("#checkAll").click(function() {
$('input[name="subBox"]').attr("checked",this.checked);
});
var $subBox = $("input[name='subBox']");
$subBox.click(function(){
$("#checkAll").attr("checked",$subBox.length == $("input[name='subBox']:checked").length ? true : false);
});
$("#allinput").click(function(){
var str="";
$("input[name='subBox']").each(function(){
if($(this).attr("checked")){
str += $(this).val()+",";}
});
alert(str);
$.ajax({
type : "post",
url : 'allout.action',
data : {//设置数据源
datasss : str
},
dataType : "json",//设置需要返回的数据类型
success : function(d) {
},
error : function(d) {
}
});
});
});
</script>
</head>
<body>
<input type="checkbox" id="checkAll" />全选
<input type="button" name="allinput" id="allinput" value="打印"/>
<form action="tianjiashangpinw.action" method="post" theme="simple">
<table border="1">
<s:iterator id="p" value="xianshilist">
<tr>
<td><input type="checkbox" name="subBox" value="<s:property value='#p.id'/>" /></td>
<td><s:property value="#p.id"/></td>
<td><s:property value="#p.sendname"/></td>
<td><s:property value="#p.sendphone"/></td>
<td><s:property value="#p.sendaddress"/></td>
<td><s:property value="#p.getname"/></td>
<td><s:property value="#p.getphone"/></td>
<td><s:property value="#p.getaddress"/></td>
</tr>
</s:iterator>
</table>
</form>
</body>
</html>
参考文章相关网址。
http://www.blogjava.net/RoyPayne/archive/2012/03/02/371115.html
http://www.oschina.net/code/snippet_119416_5689
我自己写的一个代码:http://download.csdn.net/detail/u013936945/9599707(里面包含数据库,一般来讲是直接可以跑的了)