【问题标题】:Input / Change / Keyup / focus event not fired输入/更改/按键/焦点事件未触发
【发布时间】:2018-08-01 12:57:36
【问题描述】:

我有这个功能:

showReview: function(){
            var main = document.getElementById("main");
            var ins =  main.getElementsByTagName("INPUT");
            var rev = $("reviewcontent").is(":hidden");
            for (var i = 0; i<ins.length; i++){
                $(ins[i]).on('show input keyup focus change', this.getInVals());
                console.log("Invals update from input");
            }
            if(!rev){
                this.addReview();
            }
        }

在第一次加载页面时触发事件,但在更改输入或再次关注另一个输入时不会触发。我不知道为什么。我以为它只听 main 的最后一个输入,但事实并非如此。

【问题讨论】:

    标签: javascript jquery vue.js event-handling jquery-events


    【解决方案1】:
    $(ins[i]).on('show input keyup focus change', this.getInVals());
    

    删除 getInVals 调用。尝试将getInVals() 更改为getInVals

    $(ins[i]).on('show input keyup focus change', this.getInVals);
    

    【讨论】:

    • 就是这样!非常感谢。我无法看到它。你能解释一下,我什么时候必须使用括号,什么时候不用?
    【解决方案2】:

    我不明白您要做什么或要说什么,但我正在做类似的事情,如果有帮助,您可以将其作为示例。

    $('.look').on('keyup change', function () {
        var value = $(this).val().toLowerCase();
        var what_place = $(this).parents('.collapse').find('.col-sm-0');
        $(what_place).each(function(){
            $(this).css({"display": "block"});
            if(value == ''){
                $(this).css({"display": "block"});
            }
            else if($(this).find('h5').text().toLowerCase().indexOf(value) < 0){
                $(this).css({"display": "none"});
            }
        });
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-12-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-17
      • 1970-01-01
      • 2011-12-20
      相关资源
      最近更新 更多