zoukankan      html  css  js  c++  java
  • onchange事件 is not defined

    jsp:

    <div class="input-group" style="margin-top: 10px;">
          <span class="input-group-addon" style="height: 30px;">
              <i class="fa fa-search"></i>
          </span><input id="search_input_unit" type="text" onchange="searchUnit();"
                    class="form-control" placeholder="输入内容进行检索"
                    style="height: 30px;" />
    </div>

    js:

    function searchUnit (){
        alert(1);
    }

    或者

    searchUnit = function (){
        alert(1);
    }

    提示报错:

    1 Uncaught ReferenceError: searchUnit is not defined
        at HTMLInputElement.onchange

    解决办法:删除input里的事件,并按下面写法

    js:

    function searchUnit (){
        alert(1);
    }
    $("#search_input_unit").on("change",searchUnit);

    或者

    $("#search_input_unit").on("change",function (){
        alert(1);
    });

     补:对于js拼接html,如下面这样:

    tbBody += '<tr class="' + trColor + '">' + '</td>'
                + '<td>' + n.name + '</td>' + '<td>'
                       + n.code + '</td>' + '<td>' 
           + '<button data-code="'+n.code+'" data-name="'+n.name+'" class="btn btn-outline green binding" type="button" >绑定</button>' + '</td></tr>';

    对于button事件

    $("#bill_type_table").on('click','tr>td .binding',function(){
            
    })

    直接$(".binding").on('click',function(){}) 不起作用。

    解决办法1、将上面的事件写法写到js最外层,不要在框架里面。

    解决办法2、以html或jsp已有的元素如:id="bill_type_table" 为起点,找到拼接的元素,然后定义事件。

  • 相关阅读:
    Educational Codeforces Round 97 (Rated for Div. 2)
    2020 计蒜之道 线上决赛
    kuangbin 莫队专题
    Codeforces Round #677 (Div. 3)
    Codeforces Round #674 (Div. 3)
    Elasticsearch Alias:别名
    Elasticsearch 集群重要配置的修改
    Elasticsearch文档版本冲突原理与解决
    redis操作详情
    对密码必须包含字母,数字,特殊字符正则表达式理解
  • 原文地址:https://www.cnblogs.com/x-jingxin/p/12893566.html
Copyright © 2011-2022 走看看