我试图将“焦点”事件绑定到文本框,以便每次焦点到达它时,都应调用一个函数。但是,它不会触发焦点事件。当我将光标放在文本框中时,什么也没有发生。只要单击按钮,就会触发绑定到“ click”事件的其他事件。
下面是代码段:
P.when('A', 'ready').register('dom-updater', function(A) {
var $ = A.$;
var render = function () {
if (state.widgetType === "maker") {
$('#saveData').bind('click', function(event) {
saveInfoData();
});
$('#verifyBtn').bind('click', function(event) {
validateData();
});
//This line does not work
$( "#textBoxId" ).focus(function() {
console.log( "Handler for .focus() called." );
});
} else {
//Do something else
}
};
A.on.ready(function() {
render();
});
}
我尝试使用'blur'和'focus',但是它不起作用。
$('#textBoxId').bind('blur', function(event) {
console.log("IN blur call");
});
为什么文本框未附加到焦点事件?
答案 0 :(得分:0)
$('body').on('focus', '#textBoxId', function() {
//code
console.log("IN focus call");
});
$('body').on('blur', '#textBoxId', function() {
//code
console.log("IN blur call");
});
这将起作用