点击checkbox使用js取table中tr下td中的各个标签value
来源:互联网 发布:淘宝客api开发 编辑:程序博客网 时间:2024/05/16 02:48
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!--<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
</body>
</html>-->
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>Js获取 table当前行的值</title>
<script type="text/javascript">
var selectedTr = null;//声明一个变量,用来存当前选中的行对象
//参数是选中的对象
function c1(obj) {
obj.style.backgroundColor = 'blue'; //把点到的那一行变希望的颜色;
if (selectedTr != null) {
selectedTr.style.removeAttribute("backgroundColor");
}
if (selectedTr == obj) {
selectedTr = null; //加上此句,以控制点击变白,再点击反灰
}
else {
selectedTr = obj;
}
}
/*得到选中行的第一列的值*/
function check() {
if (selectedTr != null) {//如果当前选中行为null的话
var str = selectedTr.cells[1].childNodes[0].value;
document.getElementById("lab").innerHTML = str;
}
else {
alert("请选择一行");
}
}
/*删除选中行*/
function del() {
if (selectedTr != null) {
if (confirm("确定要删除吗?")) {
alert(selectedTr.cells[0].childNodes[0].value);
var tbody = selectedTr.parentNode;
tbody.removeChild(selectedTr);
}
}
else {
alert("请选择一行");
}
}
//点击table中tr下td中的checkbox标签取到td中不同的标签的写法(备注:一个td中添加一个标签)
function checkTr(e) {
if (e.checked) {
//alert(e.parent);
var myInput = document.getElementById("td12"); //拿到td标签中的input标签
//alert(tds.parentNode.id);//输出包裹input标签的td标签的id属性
//alert(tds.parentNode.parentNode.id); //输出当前td标签的上一级td标签的id属性
alert(myInput.parentNode.parentNode.cells[0].childNodes[0].value); //cell的下标是针对tr下不同的td位置决定的
alert(myInput.parentNode.parentNode.cells[1].childNodes[0].value);
alert(myInput.parentNode.parentNode.cells[2].childNodes[0].value);
}
else {
alert("没选中");
}
}
</script>
</head>
<body>
单击选中Tr,高亮显示,再单击取消选选中。
<input type="button" value="选中的是哪一行?" onclick="check()"/>
<input type="button" value="删除选中行" onclick="del()"/>
<input type="button" value="增加一行" onclick="add()"/>
<br />
<input type="button" value="显示数据" />
<table width="100%" border="1" cellspacing="0" cellpadding="0" id="tab">
<tr bgcolor="#cccccc" id="tr1">
<td ><input type="text" value="11"/> </td>
<td id="test"><input type="text" id="td12" value="12"/> <input type="text" id="Text1" value="121"/> </td>
<td><input type="checkbox" onclick="checkTr(this)" value="13" /> </td>
</tr>
<tr onclick="c1(this);" bgcolor="#e0e0e0" id="tr2">
<td id="td2"><input type="text" value="21"/> </td>
<td><input type="text" value="22"/></td>
<td><input type="checkbox" onclick="check()" /> </td>
</tr>
<tr onclick="c1(this);" bgcolor="#cccccc" id="tr3">
<td ><input type="text" value="31"/></td>
<td><input type="text" value="32"/> </td>
<td><input type="checkbox" onclick="check()" /> </td>
</tr>
<tr bgcolor="#e0e0e0" id="tr4">
<td >
<input type="text" value="41"/>
</td>
<td>
<input type="text" value="42"/>
</td>
<td><input type="checkbox" onclick="check()" /> </td>
</tr>
<tr onclick="c1(this);" bgcolor="#cccccc" id="tr5">
<td >
<input type="text" value="51"/>
</td>
<td >
<input type="text" value="52"/>
</td>
<td><input type="checkbox" onclick="check()" /> </td>
</tr>
</table>
<label id="lab"></label>
</body>
</html>
- 点击checkbox使用js取table中tr下td中的各个标签value
- table标签中tr和td的英文单词
- 遍历table中的tr td
- HTML+CSS基础 table中的tr中的td标签中的valign属性设置文本靠上,中间,靠下
- jQuery 遍历Table中tr中的td中的内容
- JS将table中的td标签值去重
- 用js怎么取table中的tr标签--这是一个陷阱
- JQuery 在table中点击TR选中checkbox。
- ListView中使用table-tr-td布局展示数据
- HTML中table的属性tr、th、td的使用
- Angularjs中table中实现点击td中按钮不触发tr的点击事件
- js获取table下的tr和td,并且设置某个td里的文字样式
- HTML5(七)表格-table标签、tr标签、td标签
- 点击table中的某一个td,获得这个tr的所有数据
- Table tr td th表格使用案例
- Table tr td th表格使用案例
- 去除 struts2 标签中的自动生成的布局样式table/tr/td
- 去除 struts2 标签中的自动生成的布局样式table/tr/td+ 全选 反选
- innoDB锁问题-《深入浅出Mysql--数据库开发、优化与管理维护》
- shell 中for的测试脚本
- JAVA冒泡排序
- xml文件的解析--libxml库函数解析
- MTK feature phone 音频参数配置
- 点击checkbox使用js取table中tr下td中的各个标签value
- kernel 学习 : 文件系统
- DEDECMS5.7安装后首页慢或无法生成首页的解决办法
- mysql my.ini
- oracle 10g数据库介绍
- 使用 py2app 把 python 项目打包成mac下可执行的应用
- CSS:区分IE版本的三个方法
- Load generator连接失败的解决办法!
- js 处理 ie和firefox window.frames 兼容问题