【问题标题】:Can't bind 'onchange' event on div inside ul无法在 ul 内的 div 上绑定“onchange”事件
【发布时间】:2014-07-25 14:52:12
【问题描述】:

我有这个 html:

<ul>
<li>
    <a href="#">
        <div></div>
        Actions
        <div></div>
    </a>
    <ul>
        <li>
            <a>
                <div></div>
                Create New Entry
            </a>
        </li>
    </ul>
</li>
<li>
    <span>Client:<span>
    <select data-filter-name="clients" id="client_filter">
    <option value="0" {if $selectedClient == 0} selected {/if}>All</option>
    {foreach from=$clients key=k item=client}
    <option value="{$k}" {if $selectedClient == $k} selected {/if}>{$client}</option>
    {/foreach}
    </select>
</li>

在 JS 中,我试过这个:

$(document).ready(function() {
    $('#client_filter').on('change', function(){
        window.location = "/index.php?client_id=" +  $(this).val();
   });
});

并且未附加事件“onchange”! 当我单击选择框时,没有任何反应。为什么? 如果我将选择框放在外面,它就可以工作。

【问题讨论】:

    标签: jquery html html-lists bind onchange


    【解决方案1】:

    你没有关闭更改功能

    $(document).ready(function() {
    $('#client_filter').on('change', function(){
        window.location = "/index.php?client_id=" +  $(this).val();
    })//end change function
    })//end ready
    

    【讨论】:

    • 没关系,我只是拿了一个sn-p的代码......它会显示一个错误,我没有得到任何!
    【解决方案2】:

    关闭你的函数

    $(document).ready(function() {
        $('#client_filter').on('change', function(){
            window.location = "/index.php?client_id=" +  $(this).val();
        });
    
    });
    

    【讨论】:

      【解决方案3】:

      您缺少事件处理程序的右括号。

      $(document).ready(function() {
          $('#client_filter').on('change', function(){
              window.location = "/index.php?client_id=" +  $(this).val();
          });
      });
      

      【讨论】:

        猜你喜欢
        • 2023-02-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-05-02
        • 1970-01-01
        相关资源
        最近更新 更多