js怎么得到动态表格某一行的id值?

tzb08 2009-03-06 01:16:50
如题 谢谢!
...全文
1892 17 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
hey_go 2011-12-02
  • 打赏
  • 举报
回复
有没有或得动态表格一整行内容的方法啊
rjjlxy 2011-08-30
  • 打赏
  • 举报
回复
看的不太懂。。、。。
lizhengguo992003 2009-11-26
  • 打赏
  • 举报
回复
哦·····
tzb08 2009-03-06
  • 打赏
  • 举报
回复
[Quote=引用 12 楼 yixianggao 的回复:]
L@_@K
<!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> new document </title>
<meta name="generator" content="editplus" />
<meta name="author" content="" />
<meta name="keywords" content="" />
<meta name="description" content="" />
<script type="text/javasc…
[/Quote]

太谢谢yixianggao了,好猛哦!
yixianggao 2009-03-06
  • 打赏
  • 举报
回复
L@_@K
<!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> new document </title>
<meta name="generator" content="editplus" />
<meta name="author" content="" />
<meta name="keywords" content="" />
<meta name="description" content="" />
<script type="text/javascript">
<!--
function editToolAmount(oLink)
{
var tr = oLink.parentNode.parentNode;

//alert(tr.cells[1].innerHTML);
alert("tool.code = " + tr.getElementsByTagName("input")[0].value);
alert("toolAmount = " + tr.getElementsByTagName("input")[1].value);
alert("baseLend.serialNumber = " + tr.getElementsByTagName("input")[2].value);

//tr.cells[1].innerHTML = 100;
//tr.getElementsByTagName("input")[1].value = 100;
}
//-->
</script>
</head>

<body>
<table align="center" id="t">
<tr>
<td>工具条形码</td>
<td>工具数量</td>
<td>操作</td>
</tr>

<tr>
<input type="hidden" name="tool.code" value="111" id="p1"/>
<input type="hidden" name="toolAmount" value="1" id="p2"/>
<input type="hidden" name="baseLend.serialNumber" value="183" id="p3"/>
<td>111</td>
<td>1</td>
<td align="center">
<a href="#" onClick="editToolAmount(this);">修改</a>
<a href="/jtm/operatorAction!delete.action?serialNumber=183&toolCode=111&toolAmount=1" onclick="if(!confirm('确认删除么?可千万要慎重哦,如果误删了会很麻烦哦')) return false">删除</a>
</td>
</tr>

<tr>
<input type="hidden" name="tool.code" value="11111" id="p1"/>
<input type="hidden" name="toolAmount" value="1" id="p2"/>
<input type="hidden" name="baseLend.serialNumber" value="183" id="p3"/>
<td>11111</td>
<td>1</td>
<td align="center">
<a href="#" onClick="editToolAmount(this);">修改</a>
<a href="/jtm/operatorAction!delete.action?serialNumber=183&toolCode=11111&toolAmount=1" onclick="if(!confirm('确认删除么?可千万要慎重哦,如果误删了会很麻烦哦')) return false">删除</a>
</td>
</tr>
</table>
</body>
</html>
yixianggao 2009-03-06
  • 打赏
  • 举报
回复
L@_@K
<!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> new document </title>
<meta name="generator" content="editplus" />
<meta name="author" content="" />
<meta name="keywords" content="" />
<meta name="description" content="" />
<script type="text/javascript">
<!--
function editToolAmount(oLink)
{
var tr = oLink.parentNode.parentNode;

alert(tr.cells[1].innerHTML);
alert(tr.getElementsByTagName("input")[1].value);

tr.cells[1].innerHTML = 100;
tr.getElementsByTagName("input")[1].value = 100;

alert(tr.cells[1].innerHTML);
alert(tr.getElementsByTagName("input")[1].value);
}
//-->
</script>
</head>

<body>
<table align="center" id="t">
<tr>
<td>工具条形码</td>
<td>工具数量</td>
<td>操作</td>
</tr>

<tr>
<input type="hidden" name="tool.code" value="111" id="p1"/>
<input type="hidden" name="toolAmount" value="1" id="p2"/>
<input type="hidden" name="baseLend.serialNumber" value="183" id="p3"/>
<td>111</td>
<td>1</td>
<td align="center">
<a href="#" onClick="editToolAmount(this);">修改</a>
<a href="/jtm/operatorAction!delete.action?serialNumber=183&toolCode=111&toolAmount=1" onclick="if(!confirm('确认删除么?可千万要慎重哦,如果误删了会很麻烦哦')) return false">删除</a>
</td>
</tr>

<tr>
<input type="hidden" name="tool.code" value="11111" id="p1"/>
<input type="hidden" name="toolAmount" value="1" id="p2"/>
<input type="hidden" name="baseLend.serialNumber" value="183" id="p3"/>
<td>11111</td>
<td>1</td>
<td align="center">
<a href="#" onClick="editToolAmount(this);">修改</a>
<a href="/jtm/operatorAction!delete.action?serialNumber=183&toolCode=11111&toolAmount=1" onclick="if(!confirm('确认删除么?可千万要慎重哦,如果误删了会很麻烦哦')) return false">删除</a>
</td>
</tr>
</table>
</body>
</html>
tzb08 2009-03-06
  • 打赏
  • 举报
回复

<input type="hidden" name="tool.code" value="11111" id="p1"/>
<input type="hidden" name="toolAmount" value="1" id="p2"/>
<input type="hidden" name="baseLend.serialNumber" value="183" id="p3"/>

目的修改“工具数量”,主要想得到上面3个隐藏字段的值,去查询session并更新对应的“工具数量”(dwr实现的ajax功能)


zizhuxianzi 2009-03-06
  • 打赏
  • 举报
回复
才遇到这个问题!
yixianggao 2009-03-06
  • 打赏
  • 举报
回复
一旦循环 id 值就重复了——那id还有什么意义?!
也就得不到某行要的数据了——你要取那些数据,或者说你具体要执行哪些操作?
tzb08 2009-03-06
  • 打赏
  • 举报
回复

<table align="center" id="t">
<tr>
<td>工具条形码</td>
<td>工具数量</td>
<td>操作</td>
</tr>

<tr>
<input type="hidden" name="tool.code" value="111" id="p1"/>
<input type="hidden" name="toolAmount" value="1" id="p2"/>
<input type="hidden" name="baseLend.serialNumber" value="183" id="p3"/>
<td>111</td>
<td>1</td>

<td align="center">

<a href="#" onClick="editToolAmount();">修改</a>





<a href="/jtm/operatorAction!delete.action?serialNumber=183&toolCode=111&toolAmount=1" onclick="if(!confirm('确认删除么?可千万要慎重哦,如果误删了会很麻烦哦')) return false">删除</a>
</td>
</tr>

<tr>
<input type="hidden" name="tool.code" value="11111" id="p1"/>
<input type="hidden" name="toolAmount" value="1" id="p2"/>
<input type="hidden" name="baseLend.serialNumber" value="183" id="p3"/>
<td>11111</td>
<td>1</td>

<td align="center">

<a href="#" onClick="editToolAmount();">修改</a>





<a href="/jtm/operatorAction!delete.action?serialNumber=183&toolCode=11111&toolAmount=1" onclick="if(!confirm('确认删除么?可千万要慎重哦,如果误删了会很麻烦哦')) return false">删除</a>
</td>
</tr>

</table>


一旦循环 id值就重复了,也就得不到某行要的数据了
luojihaidao 2009-03-06
  • 打赏
  • 举报
回复
UP
tzb08 2009-03-06
  • 打赏
  • 举报
回复
不好意思,我说的不够明朗,
我的jsp:


<s:iterator value="%{list}" status="li">
<s:textfield id="id" name="baseLend.serialNumber" label="tool" />
<a href="#" onClick="edit();">修改</a>
<s:iterator/>




在循环里面,上面的id是没法知道的吧?我现在想通过点击“修改”来得到id,从而通过id来得到对应那一行的数据
tzb08 2009-03-06
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 yixianggao 的回复:]
L@_@K
HTML code<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><htmlxmlns="http://www.w3.org/1999/xhtml"><head><title>new document</title><metaname="generator"content="editplus"/><metaname="author"content=""/><metaname="keywords"content=""/><metaname="description"content=""/></head><body><tableid="tabTest"><tr><td>No.0</td…
[/Quote]

大哥你的代码我看的不太明白,能简单的说下嘛 谢谢了!
dyydingding 2009-03-06
  • 打赏
  • 举报
回复
楼上yixianggao
正解!!

up
yixianggao 2009-03-06
  • 打赏
  • 举报
回复
L@_@K
<!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> new document </title>
<meta name="generator" content="editplus" />
<meta name="author" content="" />
<meta name="keywords" content="" />
<meta name="description" content="" />
</head>

<body>
<table id="tabTest">
<tr>
<td>No.0</td>
<td>a</td>
</tr>
<tr>
<td>No.1</td>
<td>b</td>
</tr>
<tr>
<td>No.2</td>
<td>c</td>
</tr>
</table>
</body>
<script type="text/javascript">
<!--
function $(sId)
{
return document.getElementById(sId);
}
var oTab = $("tabTest");
for (var i=0; i<oTab.rows.length; i++)
{
oTab.rows[i].onclick = function() {
alert("这是第"+this.rowIndex+"行");
};
}
//-->
</script>
</html>
tzb08 2009-03-06
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 Free_Wind22 的回复:]
JScript codevartable=document.getElementById("表格ID");varid=table.rows[行号].cells[列号].id;
[/Quote]

谢谢! 你上面写的那个行号怎么得到的?

关键不知道某行的id值,是动的
2009-03-06
  • 打赏
  • 举报
回复

var table = document.getElementById("表格ID");
var id = table.rows[行号].cells[列号].id;

87,997

社区成员

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

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