0

我有几个下拉框。有什么方法可以检测使用 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
  });
});
4

2 回答 2

3

阿司匹林是对的,

我只会改进他的答案。

$(document).ready(function() {
  $('#products select').change(function() {
     var id = $(this).attr('id');
     var value = $(this).val();
     alert('ID ='+id+' Value ='+value);
  });
});
于 2012-07-26T10:18:50.807 回答
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);
  });
});
于 2012-07-26T10:10:00.767 回答