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.
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
. 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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.