Re: [問題] jQuery如何抓取select值
※ 引述《johe5678 (鏡花水月)》之銘言:
: 各位前輩好~
: 最近小弟在寫jsp時用JSTL的forEach(迴圈)讀資料庫產品資料。
: 要抓使用者點選select value後button送出的值,因為資料用迴圈讀出
: 所以用document.getElementById("xxxx").value只會讀出第一個資料送出的value
: 其他的資料選的select value按button都沒效.
: 找了網路上資料看到用array跟迴圈+document.getElementsByName().value可以解決,看
: 起來很麻煩.
: 想問換jQuery是否有方法快速抓到選取數量的值,謝謝~
//↓可以設class當selector 如果還有其它的button
$("input[type='button']").click(function(){
var option =
$(this).parents('table').find("select[name='orderOption']").val();
alert(option);
});
Demo http://www.jsfiddle.net/HtZAH/
每個id值都是唯一的 不宜重覆 因此要寫成id="xx1", id="xx2"之類的
另外我不確定table裡再包table 是不是好作法 不過看起來是ok的
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.122.30.198
推
11/23 11:33, , 1F
11/23 11:33, 1F
推
11/23 11:49, , 2F
11/23 11:49, 2F
→
11/23 11:50, , 3F
11/23 11:50, 3F
→
11/23 11:53, , 4F
11/23 11:53, 4F
→
11/23 12:49, , 5F
11/23 12:49, 5F
→
11/23 13:07, , 6F
11/23 13:07, 6F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 5 篇):
Ajax 近期熱門文章
PTT數位生活區 即時熱門文章