jQuery的获取值从多个共同选择 [英] jQuery getting values from multiple selects together
问题描述
我有以下code,基本上,当选择的值更改我希望能够采取新的值,并将其添加到现有的值(或减去它)。
I've got the following code which basically when the value of the select is changed I want to be able to take the new value and add it to the already existing value (or minus it).
我有一个问题实际上是抓住了价值。我有这个创建选择列表:
I'm having an issue actually grabbing the value. I have this to create the select lists:
<li class="extraHeight">
<asp:Image runat="server" CssClass="iconImageMove" ID="Image14" ImageUrl="~/images/icons/carpark_off.png" />
<div class="flipWidth">
<select name="access" class="change" id="carpark_off" runat="server">
<option value="0">Off</option>
<option value="256">On</option>
</select>
</div> <br /> <p class="noWrap">Accessible Car parking facilities</p>
</li>
<li class="extraHeight">
<asp:Image runat="server" CssClass="iconImageMove" ID="Image15" ImageUrl="~/images/icons/parking_off.png" />
<div class="flipWidth">
<select name="access" class="change" id="parking_off" runat="server">
<option value="0">Off</option>
<option value="33554432">On</option>
</select>
</div> <br /> <p class="noWrap">Customer Car parking facilities</p>
</li>
<li class="extraHeight">
<asp:Image runat="server" CssClass="iconImageMove" ID="Image16" ImageUrl="~/images/icons/staff_off.png" />
<div class="flipWidth">
<select name="access" class="change" id="staff_off" runat="server">
<option value="0">Off</option>
<option value="8192">On</option>
</select>
(有很多,但,给你一个想法)
(There are a lot more but that gives you an idea)
我使用jQuery的下面一个检测到变化并试图抢的价值,但它不工作:
I'm using the following jQuery to detect the change and try and grab the value but it's not working:
<script>
var value = $("select").val()
$("select").change(function () {
alert(value);
})
</script>
任何建议将真正成为AP preciated!
Any suggestions would really be appreciated!
汤姆
推荐答案
您只选择初始值。你需要得到改变事件中的价值。
You are only selecting the initial value. You need to get the value inside the change event.
$("select").change(function () {
var value = $(this).val()
alert(value);
})
这篇关于jQuery的获取值从多个共同选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!