0

我想获取下拉列表的值。我正在使用 msDropDown,但我将其值设为未定义。html如下:

 <select name="category[]" 
         id="webmenus_<?php echo $BPackageCityRelatedToCountry[$i]['city_id']; ?>"      
         onchange="showValue(this.value)"
 >
     <option value="0" selected="selected" title="Please select hotel category"></option>
     <option value="5_<?php echo $BPackageCityRelatedToCountry[$i]['city_id']; ?>" title="/public/front_end/images/5star.png"></option>
     <option value="4_<?php echo $BPackageCityRelatedToCountry[$i]['city_id']; ?>" title="/public/front_end/images/4star.png"></option>
     <option value="3_<?php echo $BPackageCityRelatedToCountry[$i]['city_id']; ?>" title="/public/front_end/images/3star.png"></option>
     <option value="2_<?php echo $BPackageCityRelatedToCountry[$i]['city_id']; ?>" title="/public/front_end/images/2star.png"></option>
     <option value="1_<?php echo $BPackageCityRelatedToCountry[$i]['city_id']; ?>" title="/public/front_end/images/1star.png"></option>
</select>

jquery alert($("input[name='category[]']").val());未定义的警报。

我怎样才能得到下拉列表的值?谢谢,

4

3 回答 3

2
$(":input[name='category[]']").val()
于 2012-10-23T07:58:42.013 回答
1

尝试

 $("class of select ").change(function() {
        alert($(this).val());
    });
于 2012-10-23T07:50:34.943 回答
1

您使用select而不是input

编辑您的 HTML 并将 select Tag 设置为 mutiple

 <select name="test" multiple>
     <option value="1">ITEM 1</option>
      <option value="2">ITEM 2</option>
      <option value="3">ITEM 3</option>
  </select>

alert($('select[name="test"]').val());
// outputs 1,2,3 when you select all three options
于 2012-10-23T07:54:46.113 回答