javascript如何获取text控件的值

victory06057231 2013-11-28 10:06:28
代码如下,想点击每个按钮时,获得同级的text的值,test函数里面要怎么写?

<?php

/*
* Created on 2013-11-28
*
* To change the template for this generated file go to
* Window - Preferences - PHPeclipse - PHP - Code Templates
*/
?>
<script type="text/javascript" >
function test(obj){

}

</script>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
</head>
<body>
<table name="t1">
<tr>

<input type="submit" name="submit" onclick="test(this)"/>
<input type="text" id="text" name="text" value=""/>
</tr>
</table>
<table name="t1">
<tr>
<input type="text" id="text" name="text" value=""/>
<input type="submit" name="submit" onclick="test(this)"/>

</tr>
</table>
<table name="t1">
<tr>
<input type="text" id="text" value=""/>
<input type="submit" name="submit" name="text" onclick="test(this)"/>

</tr>
</table>

</body>
</html>
...全文
289 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
hch126163 2013-12-02
  • 打赏
  • 举报
回复
function test(obj){ var elem = obj.parentNode.getElementsByName("test")[0]; }
liyajuan521 2013-11-29
  • 打赏
  • 举报
回复
学习了呃真棒,谢谢
l676331991 2013-11-28
  • 打赏
  • 举报
回复
一个文档下元素的id必须唯一,不能出现这么多id="text" 好在name可以相同。 还有,tr下只能放th或td,不能直接跟input元素。 还还有,name属性现在一般只用在表单元素上。

function test(obj){
    var elem = obj.parentNode.getElementsByName("test").item(0);         
}

87,910

社区成员

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

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