Jquery 操作table 相关代码
2014-09-19 13:28
302 查看
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'table.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<style>
.hover {
background: #bcd4ec;
}
</style>
<script type="text/javascript" src="js/jquery-1.4.2.js"></script>
</head>
<body>
<table class="table1">
<thead>
<th class="table1th1">全选<input id="qx" onclick="aa()" type="checkbox"/></th>
<th>11</th>
<th>22</th>
<th>33</th>
<th>44</th>
</thead>
<tbody>
<tr>
<td class="table1check"><input name="ck" type="checkbox"/></td>
<td>
aaaaaaa
</td>
<td>
vvvvvvv
</td>
<td>
ddddddd
</td>
<td>
cccccccc
</td>
</tr>
<tr>
<td class="table1check"><input name="ck" type="checkbox"/></td>
<td>
dddddd
</td>
<td>
dddddd
</td>
<td>
ddwweeee
</td>
<td>
eeeeeee
</td>
</tr>
<tr>
<td class="table1check"><input name="ck" type="checkbox"/></td>
<td>
eeeeeee
</td>
<td>
eeeeeee
</td>
<td>
eeeeeeeww
</td>
<td>
ggggggggg
</td>
</tr>
</tbody>
</table>
<div>
<input type="button" value="添加" onclick="add1()"/>
<input type="button" value="删除" onclick="delete1()"/>
<input type="button" value="第一行后添加" onclick="add2()"/>
</div>
<br>
</body>
</html>
<script>
var flag =false;
//全选
$("#qx").click(function(){
var flag= $("#qx").attr("checked");
if(flag){
//取消
$(".table1 input[type='checkbox']").attr("checked",true);
}else{
$(".table1 input[type='checkbox']").attr("checked",false);
}
});
//单双行颜色不一样
$(".table1 tbody tr:odd").css("background-color", "#bbf");
$(".table1 tbody tr:even").css("background-color", "#ffc");
//鼠标进入时,样式改变
$(".table1 tbody tr").hover(function() {
$(this).children("td").addClass("hover");
}, function() {
$(this).children("td").removeClass("hover")
});
var sdf=false;
//1行任意位置点击,选中这行
$(".table1 tbody tr").click(function(){
var check=$(this).children().first().children().first();
if($(this).children().first().children().first().attr("checked")){
$(this).children().first().children().first().attr("checked", false);
}else{
$(this).children().first().children().first().attr("checked", true);
}
});
//由于冲突,添加checkbox的点击事件
$("input[name='ck']").click(function(){
var check=$(this).attr("checked");
$(this).attr("checked",!check);
})
//最后添加1行
function add1(){
var tr=$(".table1 tr:eq(1)");
$(".table1 tbody").append(tr.clone());
}
//删除制定的行
function delete1(){
$(".table1 tr:eq(1)").remove();
}
//某行添加行
function add2(){
var tr=$(".table1 tr:eq(1)");
$(".table1 tr:eq(2)").after(tr.clone());
}
</script>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'table.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<style>
.hover {
background: #bcd4ec;
}
</style>
<script type="text/javascript" src="js/jquery-1.4.2.js"></script>
</head>
<body>
<table class="table1">
<thead>
<th class="table1th1">全选<input id="qx" onclick="aa()" type="checkbox"/></th>
<th>11</th>
<th>22</th>
<th>33</th>
<th>44</th>
</thead>
<tbody>
<tr>
<td class="table1check"><input name="ck" type="checkbox"/></td>
<td>
aaaaaaa
</td>
<td>
vvvvvvv
</td>
<td>
ddddddd
</td>
<td>
cccccccc
</td>
</tr>
<tr>
<td class="table1check"><input name="ck" type="checkbox"/></td>
<td>
dddddd
</td>
<td>
dddddd
</td>
<td>
ddwweeee
</td>
<td>
eeeeeee
</td>
</tr>
<tr>
<td class="table1check"><input name="ck" type="checkbox"/></td>
<td>
eeeeeee
</td>
<td>
eeeeeee
</td>
<td>
eeeeeeeww
</td>
<td>
ggggggggg
</td>
</tr>
</tbody>
</table>
<div>
<input type="button" value="添加" onclick="add1()"/>
<input type="button" value="删除" onclick="delete1()"/>
<input type="button" value="第一行后添加" onclick="add2()"/>
</div>
<br>
</body>
</html>
<script>
var flag =false;
//全选
$("#qx").click(function(){
var flag= $("#qx").attr("checked");
if(flag){
//取消
$(".table1 input[type='checkbox']").attr("checked",true);
}else{
$(".table1 input[type='checkbox']").attr("checked",false);
}
});
//单双行颜色不一样
$(".table1 tbody tr:odd").css("background-color", "#bbf");
$(".table1 tbody tr:even").css("background-color", "#ffc");
//鼠标进入时,样式改变
$(".table1 tbody tr").hover(function() {
$(this).children("td").addClass("hover");
}, function() {
$(this).children("td").removeClass("hover")
});
var sdf=false;
//1行任意位置点击,选中这行
$(".table1 tbody tr").click(function(){
var check=$(this).children().first().children().first();
if($(this).children().first().children().first().attr("checked")){
$(this).children().first().children().first().attr("checked", false);
}else{
$(this).children().first().children().first().attr("checked", true);
}
});
//由于冲突,添加checkbox的点击事件
$("input[name='ck']").click(function(){
var check=$(this).attr("checked");
$(this).attr("checked",!check);
})
//最后添加1行
function add1(){
var tr=$(".table1 tr:eq(1)");
$(".table1 tbody").append(tr.clone());
}
//删除制定的行
function delete1(){
$(".table1 tr:eq(1)").remove();
}
//某行添加行
function add2(){
var tr=$(".table1 tr:eq(1)");
$(".table1 tr:eq(2)").after(tr.clone());
}
</script>
相关文章推荐
- JQuery 操作/获取table具体代码
- JQuery 操作/获取table具体代码
- jQuery通过ajax请求php遍历json数组到table中代码(推荐)的相关资料
- 一个JQuery操作Table的代码分享
- JS(JQuery)操作Table的相关方法
- JQuery select控件的相关操作实现代码
- Visual Studio 2017中使用正则修改部分内容 如何使用ILAsm与ILDasm修改.Net exe(dll)文件 C#学习-图解教程(1):格式化数字字符串 小程序开发之图片转Base64(C#、.Net) jquery遍历table为每一个单元格取值及赋值 。net加密解密相关方法 .net关于坐标之间一些简单操作
- JQuery select控件的相关操作实现代码
- jquery设置并获取select的相关操作的代码编写
- 一个JQuery操作Table的代码分享
- jquery select操作的日期联动实现代码
- jquery 操作单选框,复选框,下拉列表实现代码
- jquery下操作HTML控件的实现代码
- 链表相关操作代码实现
- jquery操作radio/checkbox/select 及其相关
- JQUERY操作JSON实例代码
- jquery 子窗口操作父窗口的代码
- jQuery 相关控件的事件操作分解
- JQuery 构建客户/服务分离的链接模型中Table分页代码效率初探
- 个人学习代码保存:例3. GridView相关练习操作