table 里面的 checkbox 全选,取消,单选,选中一行后选中行高亮
2012-11-07 15:46
134 查看
<script type="text/javascript">
//复选框
$(function () {
//表头中的checkbox (全选 反选)
$("#cb1").click(function () {//thead>tr th:first :checkbox:first
//判断当前是否选中
var hasSelected = $("#cb1").attr("checked");
//如果没选中,则移出clickedtr类,否则就加上clickedtr类
$('tbody>tr')[hasSelected ? "addClass" : "removeClass"]("clickedtr").find(':checkbox').attr('checked', hasSelected); ;
if (hasSelected) {
// $('tbody>tr :checkbox').attr("checked", true); // $("th:first :checkbox:first").attr("checked", true);
//$("#selCheckbox").attr("checked", true);
}
else { // $('tbody>tr :checkbox').attr("checked", false); //$("th:first :checkbox:first").attr("checked", false);
//$("#selCheckbox").attr("checked", false);
}
});
$("#trid", this).click(function () {//tbody>tr, 直接给 tbody 里面的tr 命一个id=trid,然后这里用这个id
//判断当前是否选中
var hasSelected = $(this).hasClass("clickedtr");
//如果选中,则移出selected类,否则就加上selected类 //find 是 查找内部的checkbox,设置对应的属性。
$(this)[hasSelected ? "removeClass" : "addClass"]("clickedtr").find(':checkbox').attr('checked', !hasSelected);
});
// 练习可以用这种方法 $(this).find("#selCheckbox").attr("checked", "checked");
// $(this).find("#selCheckbox").removeAttr("checked");
});
$(function () {
$("tr").addClass("clicktr"); //添加css,鼠标放到tr上为手型,css里面的
$("tr").click(function () {
//$("tr").removeClass("clickedtr"); //去掉所有的clickedtr样式
// $(this).addClass("clickedtr"); //单击某tr后,将该行的颜色标记下
});
});
</script>
ViewBag.Title = "泰鸿库存管理首页";
}
<h2>泰鸿科技
@Html.ActionLink("添加商品", "Create")
<table id="tb1">
<tr style="height:25px;">
<th>
<input type="checkbox" id="cb1" />
</th>
<th>
商品名称
</th>
<th>
商品编号
</th>
<th>
入库时间
</th>
<th>
出库时间
</th>
<th>
操作时间
</th>
<th>
记录者
</th>
<th>
仓库编号
</th>
<th>
商品数量
</th>
<th style=" width:200px;">
备注
</th>
<th style=" width:200px;">
状态
</th>
<th></th>
</tr>
@foreach (var item in Model)
{
<tr style=" height:25px;"id="trid">
<td style=" width:20px;">
<input id="selCheckbox" type="checkbox"/>
</td>
<td>
@Html.DisplayFor(modelItem =>item.CommodityName)
</td>
<td>
@Html.DisplayFor(modelItem =>item.CommodityID)
</td>
<td>
@Html.DisplayFor(modelItem =>item.PutInStartDate)
</td>
<td>
@Html.DisplayFor(modelItem => item.OutEndDate)
</td>
<td>
@Html.DisplayFor(modelItem =>item.OperateDate)
</td>
<td>
@Html.DisplayFor(modelItem =>item.RecorderName)
</td>
<td>
@Html.DisplayFor(modelItem =>item.WarehouseID)
</td>
<td>
@Html.DisplayFor(modelItem =>item.CommodityNum)
</td>
<td style=" width:200px;white-space:nowrap;height:25px; overflow:hidden; ">
@Html.DisplayFor(modelItem =>(item.Commands))
</td>
<td style="width:50px;">
@Html.DisplayFor(modelItem =>item.WarehouseStatus)
</td>
<td>
@Html.ActionLink("修改", "CommodityEditByID", new { CommodityID =item.CommodityID }) |
@* @Html.ActionLink("详细信息","CommodityDetails", new { CommodityID = item.CommodityID })|*@
@* @Html.ActionLink("删除", "CommodityDelete", new { CommodityID =item.CommodityID })
*@ </td>
</tr>
}
</table>
<div id="menucontainer">
<ul id="menu">
<li><buttonid="btn_Delete">删除</button></li>
</ul>
//复选框
$(function () {
//表头中的checkbox (全选 反选)
$("#cb1").click(function () {//thead>tr th:first :checkbox:first
//判断当前是否选中
var hasSelected = $("#cb1").attr("checked");
//如果没选中,则移出clickedtr类,否则就加上clickedtr类
$('tbody>tr')[hasSelected ? "addClass" : "removeClass"]("clickedtr").find(':checkbox').attr('checked', hasSelected); ;
if (hasSelected) {
// $('tbody>tr :checkbox').attr("checked", true); // $("th:first :checkbox:first").attr("checked", true);
//$("#selCheckbox").attr("checked", true);
}
else { // $('tbody>tr :checkbox').attr("checked", false); //$("th:first :checkbox:first").attr("checked", false);
//$("#selCheckbox").attr("checked", false);
}
});
$("#trid", this).click(function () {//tbody>tr, 直接给 tbody 里面的tr 命一个id=trid,然后这里用这个id
//判断当前是否选中
var hasSelected = $(this).hasClass("clickedtr");
//如果选中,则移出selected类,否则就加上selected类 //find 是 查找内部的checkbox,设置对应的属性。
$(this)[hasSelected ? "removeClass" : "addClass"]("clickedtr").find(':checkbox').attr('checked', !hasSelected);
});
// 练习可以用这种方法 $(this).find("#selCheckbox").attr("checked", "checked");
// $(this).find("#selCheckbox").removeAttr("checked");
});
$(function () {
$("tr").addClass("clicktr"); //添加css,鼠标放到tr上为手型,css里面的
$("tr").click(function () {
//$("tr").removeClass("clickedtr"); //去掉所有的clickedtr样式
// $(this).addClass("clickedtr"); //单击某tr后,将该行的颜色标记下
});
});
</script>
ViewBag.Title = "泰鸿库存管理首页";
}
<h2>泰鸿科技
@Html.ActionLink("添加商品", "Create")
<table id="tb1">
<tr style="height:25px;">
<th>
<input type="checkbox" id="cb1" />
</th>
<th>
商品名称
</th>
<th>
商品编号
</th>
<th>
入库时间
</th>
<th>
出库时间
</th>
<th>
操作时间
</th>
<th>
记录者
</th>
<th>
仓库编号
</th>
<th>
商品数量
</th>
<th style=" width:200px;">
备注
</th>
<th style=" width:200px;">
状态
</th>
<th></th>
</tr>
@foreach (var item in Model)
{
<tr style=" height:25px;"id="trid">
<td style=" width:20px;">
<input id="selCheckbox" type="checkbox"/>
</td>
<td>
@Html.DisplayFor(modelItem =>item.CommodityName)
</td>
<td>
@Html.DisplayFor(modelItem =>item.CommodityID)
</td>
<td>
@Html.DisplayFor(modelItem =>item.PutInStartDate)
</td>
<td>
@Html.DisplayFor(modelItem => item.OutEndDate)
</td>
<td>
@Html.DisplayFor(modelItem =>item.OperateDate)
</td>
<td>
@Html.DisplayFor(modelItem =>item.RecorderName)
</td>
<td>
@Html.DisplayFor(modelItem =>item.WarehouseID)
</td>
<td>
@Html.DisplayFor(modelItem =>item.CommodityNum)
</td>
<td style=" width:200px;white-space:nowrap;height:25px; overflow:hidden; ">
@Html.DisplayFor(modelItem =>(item.Commands))
</td>
<td style="width:50px;">
@Html.DisplayFor(modelItem =>item.WarehouseStatus)
</td>
<td>
@Html.ActionLink("修改", "CommodityEditByID", new { CommodityID =item.CommodityID }) |
@* @Html.ActionLink("详细信息","CommodityDetails", new { CommodityID = item.CommodityID })|*@
@* @Html.ActionLink("删除", "CommodityDelete", new { CommodityID =item.CommodityID })
*@ </td>
</tr>
}
</table>
<div id="menucontainer">
<ul id="menu">
<li><buttonid="btn_Delete">删除</button></li>
</ul>
![](http://img.my.csdn.net/uploads/201211/07/1352274611_7550.jpg)
相关文章推荐
- table里面,怎么根据checkbox选择的一行中的某个单元格的值是否为空,来判断是否该选中
- HTML之Table简约时尚CSS样式 + HTML中checkbox元素【全选】或【取消全选】、或得到选中个数全案例使用详解
- jquery实现checkbox全选,选择性勾选,以及table中点击tr中任意一行实现选中或不选中
- ext 中checkbox 无法取消选中行,全选按钮全选问题
- JS选中checkbox后获取table内一行TD所有数据的方法
- 全选、取消、2级 checkbox的选中切换
- checkbox 全部选中,和取消全选
- asp.net gridview中添加checkbox列,用于全部选中记录或取消全选
- DataGridView添加一行数据、全选、取消全选、清空数据、删除选中行
- UI - 修改tableView多选默认蓝色选中按钮 , 全选 , 取消全选
- Angular Js 里面table, checkbox制作可多选,单选的表格
- 选择tableView的某一行时,马上取消当前选中行(选中样式不保留)
- jquery checkbox 复选框多次点击判断选中状态,以及全选/取消的代码示例
- asp.net 动态生成带有checkbox 的 table ,checkbox 选中和取消 行变色
- js <table>中点击一行中任意列数据,则可以让<checkbox>选中或者取消选中
- checkbox全选/取消/选中所有奇数/反选/获得选中的值
- Js选中checkbox后获取table内一行TD所有数据
- 实现前端table中checkbox全选功能,并将选中的数据发送到后端
- Jquery删除table里面checkbox选中的多个行
- 通过Jquery全选或全部取消某个table的checkbox