Javascript 聚焦事件使用on not激发
我正在尝试对文本框的Javascript 聚焦事件使用on not激发,javascript,jquery,focusin,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
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');
}
});
});
});
});
这样做时,通常必须找到正文或使用
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');
});
}
});
});
非常感谢。尝试了这两种方法,但都没有成功。然后你必须进行一些调试,将这个.document记录到控制台中,然后查看你得到了什么。我尝试将一个输入元素添加到弹出窗口的表单字段中,它确实起了作用。var$formCopy=''$(this.document).find(“#divfrmInfo”).html($formCopy);但是({})上的$(this.document.contents().find('#txtautompletecontact');它不起作用。