jsp实现全选



对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(里面包含数据库,一般来讲是直接可以跑的了)


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值