为啥找不到table?

tian428 2009-12-04 06:15:19
2个alert都显示undifined...为什么啊?
<form method="post" name="myform" id="myform">
<table width=100% height="300" cellspacing=0 border=1 frame=box rules=rows name="list" id="list" >
<tr height=40 ondblclick="movetable(document.myform.list,'name');">
<td>HT-912</td>
<td>100</td>
</tr>
</table>
</form>
<script language="JavaScript">

function movetable(t,name)
{
alert(t);
alert(document.myform.list);

}
</script>
...全文
214 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
chen_xiangguo 2009-12-07
  • 打赏
  • 举报
回复
没有这么用的
传个id
然后方法中使用document.getElementById(id);
浴火_凤凰 2009-12-07
  • 打赏
  • 举报
回复
使用document.getElementById(id);吧
form 里面默认的情况下没有table元素
liu2835993 2009-12-05
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 sohighthesky 的回复:]
JScript codedocument.getElementById("list");//你那种写法貌似只能用在表单元素上面
[/Quote]

正解!!!
cntmi 2009-12-04
  • 打赏
  • 举报
回复
最好的方式就是用id去取document.getElementById("list");
toury 2009-12-04
  • 打赏
  • 举报
回复
<form method="post" name="myform" id="myform">
<table width=100% height="300" cellspacing=0 border=1 frame=box rules=rows name="list" id="list" >
<tr height=40 ondblclick="movetable(document.myform.list[0],'name');">
<td>HT-912 </td>
<td>100 </td>
</tr>
</table>
</form>
<script language="JavaScript">

function movetable(t,name)
{
alert(t);
alert(document.myform.list[0]);

}
</script>
sohighthesky 2009-12-04
  • 打赏
  • 举报
回复
document.getElementById("list");//你那种写法貌似只能用在表单元素上面
擒兽 2009-12-04
  • 打赏
  • 举报
回复
飘过~

很明显 document.myform.list 不存在,并且很明显 t=document.myform.list

87,910

社区成员

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

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