0

我正在尝试对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');
                         }
                    });
               });
         });
});
4

1 回答 1

1

这样做时,您通常必须找到 body 或 usecontents()才能访问内容,如

$(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');
              });
         }
    });
});
于 2014-02-25T20:36:16.343 回答