作者wjhong (M)
看板Ajax
标题Re: [JS] js一个简单的程式
时间Fri Sep 9 14:41:28 2011
<html>
<head>
<script src='
http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js' type='text/javascript'></script>
<script type="text/javascript">
function get_respon(object)
{
var pre=object.previousSibling.previousSibling;
var string=document.getElementById(pre.id).value;
$("div#result").append(string);
}
</script>
</head>
<body>
<input type='text' id='respon' value='response'/>
<input type='submit' onclick='get_respon(this);'/></br>
<div id="result"></div>
</body>
</html>
--
我成功了!!
感谢N大指点~
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.127.200.211
1F:推 No:那个..已经有设定id,就直接用id取得element就可以了 09/09 15:30
2F:→ No:或者你已经用相对位置得到<input>,也可以var string=pre.value 09/09 15:31
3F:→ wjhong:噢因为我在做类似动态回应 所以input不是固定的 09/09 15:51
4F:→ wjhong:不能用id直接取得.. 09/09 15:52
5F:推 s25g5d4:我是建议你套上回圈一直去找上一个节点 09/09 19:06
6F:→ s25g5d4:然後每跳到上一个节点就检查tag name 或其他能辨识的class 09/09 19:07
7F:→ s25g5d4:之类的 找到就跳出回圈 09/09 19:07