0
我有一個多於一個下拉列表的表單,如下所示。我可以看到如何獲取每個下拉列表的ID,但我無法弄清楚如何獲得實際使用的ID。請有人解釋如何做到這一點。如何確定使用哪個下拉列表
<div>
<select name="id[11]" class="pullDown" id="attrdrop0">
<option class="pink" value="31`">No</option>
<option class="pink" value="32">Yes (+$40.00)</option>
</select>
</div>
<div>
<select name="id[10]" class="pullDown" id="attrdrop1">
<option class="pink" value="31">No</option>
<option class="pink" value="32">Yes (+$150.00)</option>
</select>
</div>
<script>
$(function() {
$("#prices").change(function() {
console.log('A change was made');
CalculatePrice();
});
});
function CalculatePrice() {
var ttl_price = 0;
var id = '';
$(":input.select, :input").each(function() {
var cur_price = $('option:selected', $(this)).text();
ttl_price += cur_price;
id = $(this).attr('id');
/*** What now ***/
});
SetPrice(id, ttl_price);
}
</script>
謝謝,但我不認爲這會做我想要的。我試過了,它在CalculatePrice函數中顯示爲true,但它沒有標識下拉列表。 「#prices」是表單名稱,如果我在CalculatePrices函數中檢查了id變量,它只是顯示錶單名稱。我需要知道下拉ID。那可能嗎? – user3052443
也許我不理解你的解決方案,或者我把最初的代碼弄糊塗了,但是在我展示的代碼是[code]
然後你可以使用event.target:https://api.jquery.com/event.target/ – Hopesun