有n个name="abcd"的inpu,不用循环,如何知道当前的是第几个?

JK_10000 2002-10-14 02:57:45
<input name=abcd onclick="JKtest(this)">
<input name=abcd onclick="JKtest(this)">
<input name=abcd onclick="JKtest(this)">
<input name=abcd onclick="JKtest(this)">
<input name=abcd onclick="JKtest(this)">
<input name=abcd onclick="JKtest(this)">

<script>
function JKtest(obj)
{
alert("此input名为"+obj.name);
alert("这是第??????个");



}

</script>
...全文
49 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
emu 2002-10-14
  • 打赏
  • 举报
回复
如果各个网页的表格的格式都差不多的话,当然用rowIndex和cellIndex最方便了
希默软件 2002-10-14
  • 打赏
  • 举报
回复
放在表格里,一行一个,动态插入就增加一行,跟行的rowIndex一样,获得行的rowIndex。可以吗?
潇洒 2002-10-14
  • 打赏
  • 举报
回复
goldenlove(潇洒.net) :呵,不错不错

不过我的input是动态的,
要在页面上完成插入删除等操作。

欢迎继续关注

你这些操作如果是用 JS 来操作还是用后台 ??
如果是后台的话, 写个 ID 也不是什么难事啊 ??
潇洒 2002-10-14
  • 打赏
  • 举报
回复
反正要么是得有个 index 要么就得有个 name 或 id 的标记.
否则根本找不到 obj. 找不到 obj 你还怎么得到它的顺序 ?

呵... 这不像本地程序,本地程序的控件都有个TabOrder 或 TabIndex
来标识其在 form 中的顺序.
JK_10000 2002-10-14
  • 打赏
  • 举报
回复
emu(ston) :
的确是放在表格里,
但是表格别人已经写好了(有十多个网页)
我现在要打补丁将里面加上上下左右键的控制。
希望能做成一个通用的
所以希望不要太依靠其它的内容
emu 2002-10-14
  • 打赏
  • 举报
回复
动态生成的话一般放表格里面,通过cellIndex或者rowIndex来定位。
emu 2002-10-14
  • 打赏
  • 举报
回复
我建议还是用循环吧。
emu 2002-10-14
  • 打赏
  • 举报
回复
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title></title>
</head>
<body>

<input name=abcd onclick="JKtest(this)">
<input name=abcd onclick="JKtest(this)">
<input name=abcd onclick="JKtest(this)">
<input name=abcd onclick="JKtest(this)">
<input name=abcd onclick="JKtest(this)">
<input name=abcd onclick="JKtest(this)">

<script>
function JKtest(obj)
{
alert("这是第"+(obj.sourceIndex-4)+"个");
}

</script>

</body>
</html>
dustinfog 2002-10-14
  • 打赏
  • 举报
回复
把所有input设为同一id值"xx",然后取obj在数组xx[]中的index不行吗?我没做过啊,你自己试试看
JK_10000 2002-10-14
  • 打赏
  • 举报
回复
goldenlove(潇洒.net) :呵,不错不错

不过我的input是动态的,
要在页面上完成插入删除等操作。

欢迎继续关注
sun1979song 2002-10-14
  • 打赏
  • 举报
回复
呵呵,有意思,这个问题是比较有意思。要是不准打标记呢?
关注.....
潇洒 2002-10-14
  • 打赏
  • 举报
回复
嘿嘿..... 不要骂我....

<input name=abcd id=1 onclick="JKtest(this)">
<input name=abcd id=2 onclick="JKtest(this)">
<input name=abcd id=3 onclick="JKtest(this)">
<input name=abcd id=4 onclick="JKtest(this)">
<input name=abcd id=5 onclick="JKtest(this)">
<input name=abcd id=6 onclick="JKtest(this)">

<script>
function JKtest(obj)
{
alert("此input名为"+obj.name);
alert("这是第?????"+obj.id+"个");
}
</script>

87,996

社区成员

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

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