简体   繁体   English

模糊事件不适用于淘汰赛 js

[英]blur event is not working for knockout js

Scenario is that when we enter something in a textbox and put mouse anywhere on the page there should be an alert.场景是,当我们在文本框中输入内容并将鼠标放在页面上的任何位置时,应该会出现警报。 Tried with following fiddler code.尝试使用以下提琴手代码。

Can anybody please correct the following code?有人可以更正以下代码吗?

Note- I am not using hasfocus so please do not tell me to use it rather please suggest how I can use blur method.注意 - 我没有使用hasfocus所以请不要告诉我使用它,而是请建议我如何使用blur方法。

http://jsfiddle.net/bipin_pandey/2vc8X/1/ http://jsfiddle.net/bipin_pandey/2vc8X/1/

<input id="textbox" type="text" data-bind="event: { blur: blurFunction() }" />


var model = (function () {
    var self = {};
    self.blurFunction=ko.observable();
    self.blurFunction = blurmethod();
    function blurmethod() {
            alert('we are here - onblur');
    }    
    
    
    return self;
})();



ko.applyBindings(model);

Simply remove the braces () from blurmethod when your assigning it to your View-Model blurFunction .将大括号()分配给 View-Model blurFunction时,只需从blurmethod删除它。 WHy?为什么? becuase in your code your are executing the function not passing it as a parameter.因为在您的代码中,您正在执行函数而不是将其作为参数传递。 And no need either for braces () in your View.并且不需要在您的视图中使用大括号()

Working Demo工作演示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM