且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

更改其中一个下拉菜单时,如何获取所有其他下拉菜单的值

更新时间:2023-11-27 09:02:28

是否可以向div中的每个select添加一个类?像这样:

Can you add a class to each of the selects in the div? Like so:

<div id="cat1">
<select id="sel1" class="div1">
  <option  value="abc" > abc </option>
  <option  value="def" > def </option>
</select>

<select id="sel2" class="div1">
  <option  value="rst" > rst </option>
  <option  value="uvw" > uvw </option>
</select>
</div>

然后jQuery可以做到这一点:

Then the jQuery could do this:

 $('.div1').each(function() { 
            alert ('hi');  // does not even iterate
            alert($(this).val());
    });