focusin事件使用on not firing

时间:2014-02-25 20:29:18

标签: javascript jquery focusin

我正在尝试对文本框的foucsin执行某些操作。但是,由于某种原因,事件永远不会发生。

$(".ddlAddListinTo li").click(function () {
    var urlstring = "../ActionTypes";
    $.post(urlstring, function (data) {
        $(window.open(urlstring, 'Contacts', 'width=750, height=400')).load(function (e) {

      //  Here "this" will be the pop up window. 
             $(this.document).find('#txtAutocompleteContact').on({
                   'focusin': function (event) {
                   alert('You are inside the Contact text box of the Contacts Popup');
                         }
                    });
               });
         });
});

1 个答案:

答案 0 :(得分:1)

当这样做时,您通常必须找到正文或使用contents()来访问内容,如

$(this.document).contents().find('#txtAutocompleteContact')

但在这种情况下使用一个简单的javascript似乎更合适:

$(".ddlAddListinTo li").on('click', function () {
    var urlstring = "../ActionTypes";
    $.post(urlstring, function (data) {
        var wind = window.open(urlstring, 'Contacts', 'width=750, height=400');

        wind.onload = function() {
             var elem = this.document.getElementById('txtAutocompleteContact');

              $(elem).on('focus', function() {
                  alert('You are inside the Contact text box of the Contacts Popup');
              });
         }
    });
});