Фокусное событие, использующее не стрельбу

Я пытаюсь выполнить какое-то действие на 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 ответ

Делая это таким образом, вы обычно должны найти тело или использовать 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');
              });
         }
    });
});
Другие вопросы по тегам