我有几个下拉框。有没有办法检测使用jquery更改了哪个下拉列表?
<form id="products">
<select id="Ram">
<option value="0">4 GB</option>
<option value="1">8 GB</option>
</select>
<select id="Hdd">
<option value="0">300 GB</option>
<option value="1">500 GB</option>
</select>
</form>
使用Javascript / Jquery的
$(document).ready(function() {
$('#products').change(function() {
var value = $(this).val(); //In here I want to detect and return the value.
alert(value); // Want to return dropdown ID and its selected value
});
});
答案 0 :(得分:3)
$(document).ready(function() {
$('select').not('ids of select tags which you want to exclude seperated by a comma').change(function() {
var id = $(this).attr('id');
var value = $(this).val();
alert('ID ='+id+' Value ='+value);
});
});
答案 1 :(得分:3)
阿司匹林是对的,
我会改善他的答案。
$(document).ready(function() {
$('#products select').change(function() {
var id = $(this).attr('id');
var value = $(this).val();
alert('ID ='+id+' Value ='+value);
});
});