dongzhan1570
2013-11-18 10:47
浏览 182
已采纳

如何使用JQuery获取多个下拉框值

I have generated drop-down box using loop. Now I want to get all value using J-Query for pass these value for insertion through Ajax.

My HTML CODE is -

<select name="travel[]" id="travel[]"  >
     <option   value="1">Car</option>
<select>
<select name="travel[]" id="travel[]"  >
     <option   value="2">Train</option>
<select>
<select name="travel[]" id="travel[]"  >
     <option   value="3">Bus</option>
<select>

After click on Save button , how to collect all values of travel. Please Help . Thanks in Advanced.

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

4条回答 默认 最新

  • dongren7374 2013-11-18 10:51
    已采纳

    You can do this:

    var data = $('select[name="travel[]"]').map(function () {
        return $(this).val();
    }).get();
    
    console.log(data);    // ["1", "2", "3"] 
    

    This will return you an array with the value for all the dropdowns.

    Fiddle demo

    评论
    解决 无用
    打赏 举报
  • 查看更多回答(3条)

相关推荐 更多相似问题