我试图将一个“焦点”事件绑定到一个文本框,这样每次焦点到达它时,它都应该调用一个函数。 但是,它并没有触发焦点事件。 当我将光标放入文本框中时,什么也不会发生。 每当单击按钮时,就会触发绑定在“单击”事件上的其他事件。
下面是代码片段:
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();
});
}
我试过使用“模糊”和“聚焦”,但都不起作用。
$('#textBoxId').bind('blur', function(event) {
console.log("IN blur call");
});
为什么文本框没有附加到焦点事件?
$('body').on('focus', '#textBoxId', function() {
//code
console.log("IN focus call");
});
$('body').on('blur', '#textBoxId', function() {
//code
console.log("IN blur call");
});
这会管用的