对焦/模糊事件未被触发

我试图将“焦点”事件绑定到文本框,这样每次焦点到达它时,它都应该调用一个函数。但是,它不会触发焦点事件。当我将光标放入文本框中时,没有任何反应。每当单击按钮时,都会触发绑定在“单击”事件上的其他事件。


下面是代码片段:


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");

 });

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


慕神8447489
浏览 58回答 1
1回答

月关宝盒

$('body').on('focus', '#textBoxId', function() {  //code  console.log("IN focus call");});$('body').on('blur', '#textBoxId', function() {  //code  console.log("IN blur call");});这将工作
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript