焦点/模糊事件未触发

问题描述 投票:0回答:1

我正在尝试将“焦点”事件绑定到文本框,以便每次焦点到达它时,都应调用一个函数。但是,它不会触发焦点事件。当我将光标放在文本框中时,什么也没有发生。只要单击按钮,就会触发绑定到“ 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");
 });

为什么文本框未附加到焦点事件?

javascript jquery jquery-ui frontend focus
1个回答
0
投票
$('body').on('focus', '#textBoxId', function() {
  //code
  console.log("IN focus call");
});
$('body').on('blur', '#textBoxId', function() {
  //code
  console.log("IN blur call");
});

这将起作用

© www.soinside.com 2019 - 2024. All rights reserved.