php复选框提交获取

index.php

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style>
.dataTable {
	border-top: 1px solid #009286;
	border-right: 1px solid #009286;
	border-bottom: 1px solid #009286;
}

.dataTable thead tr {
	background: url(../images/topBar_bg.gif);
	font-weight: bold;
	text-align: center;
}

.dataTable tbody tr td {
	text-align: left;
	margin: 0px;
	padding: 8px;
	white-space: nowrap;
}

.dataTable .null {
	margin: 0px;
	padding: 0px;
}

.dataTable tbody tr {
	line-height: 120%;
}

.dataTable .even {
	background: #E1F4EE;
} /* 偶数行样式 E1F4EE*/
.dataTable .odd {
	background: #E1F4EE;
} /* 奇数行样式 E1F4EE*/
.dataTable .over {
	background: #CCCC99;
} /* 鼠标掠过行样式 CCCC99*/
.dataTable .selected {
	background: #6F4DFF;
	color: #ffffff;
} /* 选中行样式 BFDFFF*/
</style>

<script language=javascript
	src="http://code.jquery.com/jquery-1.4.2.min.js"></script>

<SCRIPT LANGUAGE="JavaScript">  
    <!--  
        /*   
        jQuery实现点击复选框即高亮显示选中行 全选、反选   
        详见http://www.cnblogs.com/chengulv/archive/2012/02/25/2368055.html  
        */  
        (function ($) {  
            $.fn.extend({  
                "alterBgColor": function (options) {  
                    var prevselitem = null;  
                    //设置默认值  
                    options = $.extend({  
                        style: "4",  
                        odd: "odd", /* 偶数行样式*/  
                        even: "even", /* 奇数行样式*/  
                        over: "over", /* 鼠标掠过*/  
                        selected: "selected" /* 选中行样式*/  
                    }, options);  
                    //交替背景  
                    $("tbody>tr:odd", this).addClass(options.odd);  
                    $("tbody>tr:even", this).addClass(options.even);  
                    //鼠标移动背景  
                    $("tbody>tr", this).hover(function () { $(this).addClass(options.over); }, function () { $(this).removeClass(options.over); });  
                    //初始背景 (判断第一列中有被选中的话就高亮)  
                    $("tbody>tr td:first-child:has(:checked)", this).parents('tr').addClass(options.selected);  
      
                    //样式1  
                    if (options.style == "1") {  
                        $("tbody>tr", this).click(function () { $(this).toggleClass(options.selected); });  
                    }  
      
                    //样式2  
                    if (options.style == "2") {  
                        $('tbody>tr', this).click(function () {  
                            //判断当前是否选中  
                            var hasSelected = $(this).hasClass(options.selected);  
                            //如果选中,则移出selected类,否则就加上selected类  
                            $(this)[hasSelected ? "removeClass" : "addClass"](options.selected)  
                            //查找内部的checkbox,设置对应的属性。  
                        .find(':checkbox:first').attr('checked', !hasSelected);  
                        });  
                    }  
      
                    //样式3  
                    if (options.style == "3") {  
                        // 如果单选框默认情况下是选择的,则高色.  
                        $('tbody>tr', this).click(function () {  
                            $(this).siblings().removeClass(options.selected); //除掉同胞的样式。  
                            $(this).addClass(options.selected).find(':radio:first').attr('checked', true);  
                        });  
                    }  
      
                    //样式4  
                    if (options.style == "4") {  
                        //第一列 为多选  
                        $('tbody>tr td:first-child', this).click(function () {  
                            var p = $(this).parents("tr");  
                            var hasSelected = p.hasClass(options.selected);  
                            p[hasSelected ? "removeClass" : "addClass"](options.selected).find(':checkbox:first').attr('checked', !hasSelected);  
                        });  
                        //其他列 为单选  
                        $('tbody>tr td:not(:first-child)', this).click(function () {  
                            var p = $(this).parents("tr");  
                            p.addClass(options.selected).siblings().removeClass(options.selected).find(':checkbox:first').attr('checked', false);  
                            p.find(':checkbox:first').attr('checked', true);  
                        });  
                    }  
      
      
                    //表头中的checkbox (全选 反选)  
                    $("thead>tr th:first-child :checkbox:first", this).click(function () {  
                        //判断当前是否选中  
                        var hasSelected = $(this).attr("checked");  
                        //如果选中,则移出selected类,否则就加上selected类  
                        var tab = $(this).parents("table");  
                        tab.find("tbody>tr")[!hasSelected ? "removeClass" : "addClass"](options.selected);  
                        tab.find('tbody>tr td:first-child :checkbox').attr("checked", hasSelected ? true : false);  
      
                    });  
                    return this;  //返回this,使方法可链。  
                }  
            });  
        })(jQuery);  
      
      
        $(document).ready(function () {  
            $(".dataTable").alterBgColor({ style: "4" }).find("th").css("color", "red"); //可以链式操作  
        });  
     //-->  
    </SCRIPT>
<script type="text/javascript">
function mysubmit1(){
frm.action = "1.php"
}
function mysubmit2() {
frm.action = "2.php"
}
</script>
<form method=post action="" name="frm">
	<table class="dataTable">
		<thead>
			<tr>
				<th>
					<input type="checkbox" name="tablechoice1" value="1" />
					<input type="checkbox" name="tablechoice1" value="" />
					全选
				</th>
				<th>姓名</th>
				<th>性别</th>
				<th>暂住地</th>
			</tr>
		</thead>
		<tbody>
			<tr>
				<td>
					<input type="checkbox" name="tablechoice[]" value="2" />
				</td>
				<td>张山</td>
				<td>男</td>
				<td>浙江宁波</td>
			</tr>
			<tr>
				<td>
					<input type="checkbox" name="tablechoice[]" value="3" />
				</td>
				<td>李四</td>
				<td>女</td>
				<td>浙江杭州</td>
			</tr>
			<tr>
				<td>
					<input type="checkbox" name="tablechoice[]" value="4" checked />
				</td>
				<td>王五</td>
				<td>男</td>
				<td>湖南长沙</td>
			</tr>
			
		</tbody>
	</table>
	<input type="submit" οnclick="mysubmit1()">
	<input type="submit" οnclick="mysubmit2()">
</form>
</body>
</html>

1.php

<?php

if (isset($_POST['tablechoice'])) {
    foreach ($_POST['tablechoice']as $mycheckbox ){
        echo $mycheckbox;
    }
}

?>



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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值