我想获得下拉列表的价值。我正在使用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());
警告未定义。
我如何获得下拉列表的价值? 谢谢,
答案 0 :(得分:2)
$(":input[name='category[]']").val()
答案 1 :(得分:1)
试
$("class of select ").change(function() {
alert($(this).val());
});
答案 2 :(得分:1)
您使用选择代替输入
修改HTML并将选择标记设置为多个
<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