Re: [JS] js一個簡單的程式

看板Ajax作者 (M)時間14年前 (2011/09/09 14:41), 編輯推噓2(205)
留言7則, 3人參與, 最新討論串2/2 (看更多)
<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

09/09 15:30, , 1F
那個..已經有設定id,就直接用id取得element就可以了
09/09 15:30, 1F

09/09 15:31, , 2F
或者你已經用相對位置得到<input>,也可以var string=pre.value
09/09 15:31, 2F

09/09 15:51, , 3F
噢因為我在做類似動態回應 所以input不是固定的
09/09 15:51, 3F

09/09 15:52, , 4F
不能用id直接取得..
09/09 15:52, 4F

09/09 19:06, , 5F
我是建議你套上迴圈一直去找上一個節點
09/09 19:06, 5F

09/09 19:07, , 6F
然後每跳到上一個節點就檢查tag name 或其他能辨識的class
09/09 19:07, 6F

09/09 19:07, , 7F
之類的 找到就跳出迴圈
09/09 19:07, 7F
文章代碼(AID): #1EQRKRip (Ajax)
討論串 (同標題文章)
文章代碼(AID): #1EQRKRip (Ajax)