• oninput,onpropertychange,onchange的用法和区别


    如图所示,我想在搜索框实时筛选下面选项内的选项,

    开始想到用onchange事件,但是该事件是在搜索框(input)失去焦点时,切当前对象属性发生改变时触发。

    我是需要只要内容改变就触发筛选函数,所以onchange对我这个并不实用。

    因此查阅相关事件:

    oninput,onpropertychange,onchange的用法:

      (1)lonchange触发事件必须满足两个条件:

          a)当前对象属性改变,并且是由键盘或鼠标事件激发的(脚本触发无效)

        b)当前对象失去焦点(onblur);

      (2)onpropertychange的话,只要当前对象属性发生改变,都会触发事件,但是它是IE专属的;

      (3)oninput是onpropertychange的非IE浏览器版本,支持firefox和opera等浏览器,但有一点不同,它绑定于对象时,并非该对象所有属性改变都能触发事件,它只在对象value值发生改变时奏效。

    我的需求是只要只改变就马上触发,所以用了onpropertychange和oninput事件

    html元素中添加两个事件

    <input id="search_input" oninput="searchUserList(this.value);" onpropertychange="searchUserList(this.value);" placeholder="搜索"/>

    js中添加筛选函数

    /**
     * 当驳回、改派、加签...时
     * 根据搜索框内容,过滤人员列表
     */
    var searchUserList = function(value){
        
        var $userList = $('#userList').find('.contact_person').find('span');//获取人员列表
        //$userList.closest('.contact_person').css('display', 'block');
        
        $userList.each(function(index, elem){
            
            $(this).closest('.contact_person').css('display', 'block');
        })
        
        $userList.each(function(index, elem){
            
            if($(this).text().indexOf(value) == -1){//含有该搜索字符串
                $(this).closest('.contact_person').css('display', 'none');
            }
        })
    };
  • 相关阅读:
    ML与NLP的2019年度总结与展望
    python在文本开头插入一行的实例
    Git Notes
    warmup 预热学习率
    python error整理
    python 中字符串处理
    集成学习voting Classifier在sklearn中的实现
    机器学习 评价指标整理
    PaddlePaddle Notes
    linux 常用指令 文件操作trick等
  • 原文地址:https://www.cnblogs.com/daisy-hust/p/4958741.html
Copyright © 2020-2023  润新知