js操作动态表格内元素

本文介绍了一种在页面中操作动态表格的方法,特别是在表格空间ID不断变化的情况下,如何使用JavaScript的document.getElementById()结合table.rows[i].cells[n].children[m]来获取和控制表格单元格中的数据。文章提供了具体示例代码,演示了如何遍历表格并检查特定单元格的值。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

今天碰到了个问题,页面中存在动态表格,而动态表内空间id是变化的,无法通过id或name进行获取或控制,最终通过js的document.getElementById(),及table.rows[i].cells[5].children[0]达到了目的。
示例代码如下:

	var msgBz = "提示:<br/>";
	var flagBz = true;
	var table = document.getElementById("TABLE_0");
	console.log("length:"+table.rows.length);
	for(var i=37;i<52;i++){
		var $score = table.rows[i].cells[5].children[0];
		var $item = table.rows[i].cells[2].children[0];
		var $remakes = table.rows[i].cells[7].children[0];
		console.log("score:"+$score.value);
		console.log("remakes:"+$remakes.value);
		
		if($score.value<1 && $remakes.value==""){
			//flagBz = false;
			if(msgBz.indexOf($item.value)==-1){
				msgBz += $item.value+"单项得分小于1,请填写相应备注<br/>";
				flagBz = false;
			}
		}
	}
	console.log("msgBz:"+msgBz);
	if(flagBz == false){
		alert(msgBz);
		$("html,body").animate({scrollTop:0}, 500);
		return false;
	}

参考网址:
https://blog.csdn.net/zhanqizi/article/details/83141238
http://blog.csdn.net/LPFpegfei/article/details/42143769
js带参函数,返回值函数
https://zhidao.baidu.com/question/157957425.html
https://www.cnblogs.com/xiaowie/p/9773211.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值