怎样查找html表格行里的某个input

r00_a2lBUR 2019-02-21 11:04:39
我在table(id是tableList)的tr的某个td里放了一个input,type是hidden,id是definedBgColor+所在行的序号,我用var tableList = document.getElementById("tableList")获取了这个表格的对象,在定义tableList.rows[i].onmouseout = function(){...}时,怎样能够取出所在行的definedBgColor?
...全文
152 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
風灬雲 2019-02-21
  • 打赏
  • 举报
回复
你这个隐藏input的目的是什么?就是储存backgroundColor值?为啥不用自定义属性储存
r00_a2lBUR 2019-02-21
  • 打赏
  • 举报
回复
引用 1 楼 fanghz0103 的回复:
在当前function里面用this.id获取不行吗?
this.id是怎么写?我用this.style.backgroundColor = document.getElementById("definedBgColor"+i).value();,但没有达到效果。
fanghz0103 2019-02-21
  • 打赏
  • 举报
回复
在当前function里面用this.id获取不行吗?
天际的海浪 2019-02-21
  • 打赏
  • 举报
回复

tableList.rows[i].onmouseout = function(){
	var str = this.querySelector("input[id^='definedBgColor']").value;
}

麦草CMS 2019-02-21
  • 打赏
  • 举报
回复
如果考虑兼容IE,就tableList.rows[i].querySelector("input");
麦草CMS 2019-02-21
  • 打赏
  • 举报
回复
var current;
for(var i =0, chilren = tableList.rows[i].children; i < children.length; i++){
if(children[i].nodeName == "INPUT"){
current = children[i];
break;
}
}
Hello World, 2019-02-21
  • 打赏
  • 举报
回复
可以用this.getElementsByTagName来取得指定类型的元素列表,再判断其id或者其他特征是不是你要的元素

87,914

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧