JS获得选取checkbox整行数据的方法
作者:shichen2014 时间:2024-02-26 21:10:33
本文实例讲述了JS获得选取checkbox整行数据的方法。分享给大家供大家参考。具体实现方法如下:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>js</title>
</head>
<script language="javascript">
function getTDtext()
{
var rows = document.getElementById("test_table").rows;
var a = document.getElementsByName("r");
//var states = "";
var table = document.getElementById("test_table");
for(var i=0;i<a.length;i++)
{
if(a[i].checked){
var row = a[i].parentElement.parentElement.rowIndex;
//states += rows[row].cells[1].innerHTML+";";
alert(a[i].value);
alert(rows[row].cells[1].innerHTML);
}
}
}
</script>
<body>
<table id="test_table">
<tr><td><input type="checkbox" name="r" value="1"></td><td>a</td></tr>
<tr><td><input type="checkbox" name="r" value="2"></td><td>b</td></tr>
<tr><td><input type="checkbox" name="r" value="3"></td><td>c</td></tr>
<tr><td><input type="checkbox" name="r" value="4"></td><td>d</td></tr>
<tr><td><input type="checkbox" name="r" value="5"></td><td>e</td></tr>
<tr><td><input type="checkbox" name="r" value="6"></td><td>f</td></tr>
</table>
<input type="button" onclick="getTDtext()" value="button">
</body>
</html>
希望本文所述对大家的javascript程序设计有所帮助。
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
python 通过文件夹导入包的操作
![](https://img.aspxhome.com/file/2023/6/75366_0s.jpg)
python logging多进程多线程输出到同一个日志文件的实战案例
Web 前端优化最佳实践之 Cookie 篇
IE 8 提出“超级标准模式”
python连接字符串的方法小结
Python使用scipy.fft进行大学经典的傅立叶变换
![](https://img.aspxhome.com/file/2023/3/83863_0s.png)
MySQL之information_schema数据库详细讲解
adonet基础示例分享(adonet连接数据库)
javascript用回车键实现Tab键功能
简述mysql监控组复制
账户名和密码漏输或误输的文字提示
![](https://img.aspxhome.com/file/UploadPic/20096/24/12-25s.png)
vue实现导航栏下拉菜单
![](https://img.aspxhome.com/file/2023/2/126482_0s.gif)
Python中lru_cache的使用和实现详解
Express的路由详解
perl 简明教程 perl教程集合
详解Vue用cmd创建项目
![](https://img.aspxhome.com/file/2023/9/125289_0s.png)
python 读取txt中每行数据,并且保存到excel中的实例
python绘制堆叠条形图介绍
![](https://img.aspxhome.com/file/2023/6/112516_0s.jpg)
php上传图片到指定位置路径保存到数据库的具体实现
利用python实现汉诺塔游戏
![](https://img.aspxhome.com/file/2023/3/87783_0s.jpg)