为什么onchange函数不使用Jquery调用DropDownList?

时间:2017-10-18 10:14:55

标签: javascript jquery html drop-down-menu

我想在DropDownList更改时调用更改函数。此下拉列表是动态创建的,

这是我的代码:

$('.chequeTable .selected .tbDDLReqNo').on('change', ':checkbox', function() {
  alert('yessss');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
<table class="chequeTable">
  <tr class="selected">
    <td class="tdReqNo">
      <select class="tbDDLReqNo">
        <option></option>
        <option value="1111">1111</option>
        <option value="2222">2222</option>
        <option value="3333">3333</option>
        <option value="4444">4444</option>
        <option value="5555">5555</option>
      </select>
    </td>
  </tr>
</table>

3 个答案:

答案 0 :(得分:2)

只需使用类名.tbDDLReqNo作为选择器设置下拉列表更改事件。没有checkbox因此check没有任何内容。

$('.tbDDLReqNo').on('change', function () {
    alert('yessss');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<table class="chequeTable">
    <tr class="selected">
        <td class="tdReqNo">
            <select class="tbDDLReqNo">
                 <option></option>
                 <option value="1111">1111</option>
                 <option value="2222">2222</option>
                 <option value="3333">3333</option>
                 <option value="4444">4444</option>
                 <option value="5555">5555</option>
            </select>
        </td>
    </tr>
</table>

答案 1 :(得分:1)

on方法的第二个参数是selector。因此,您必须按以下方式使用:

  

.on(events [,selector] [,data],handler)

&#13;
&#13;
$('.chequeTable').on('change','.tbDDLReqNo', function () {
    alert('yessss');
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<table class="chequeTable">
    <tr class="selected">
        <td class="tdReqNo">
            <select class="tbDDLReqNo">
                 <option></option>
                 <option value="1111">1111</option>
                 <option value="2222">2222</option>
                 <option value="3333">3333</option>
                 <option value="4444">4444</option>
                 <option value="5555">5555</option>
            </select>
        </td>
    </tr>
</table>
&#13;
&#13;
&#13;

答案 2 :(得分:0)

您也可以使用Jquery Selector:

(select distinct FOO from TABLE_A) minus (select distinct FOO from TABLE_B)
$( document ).ready(function() {
$('.tbDDLReqNo').on('change', function () {
    alert('The value has been changed! , and you have been '+$(this).val()+ ' selected.');
});
});