为什么从UpdatePanel内打开时不会弹出关闭 [英] Why doesn't the pop up close when opened from inside an UpdatePanel
问题描述
JQuery的(在我的网页表单的头部函数内部):
JQuery (inside the head function in my webform):
function DoThisEM() {
centerPopupEM();
loadPopupEM();
}
function DoThatEM() {
disablePopupEM();
}
var popupStatusEM = 0;
//loading popup with jQuery magic!
function loadPopupEM() {
//loads popup only if it is disabled
if (popupStatusEM == 0) {
$("#backgroundPopupEM").css({
"opacity": "0.7"
});
$("#backgroundPopupEM").fadeIn("slow");
$("#popupContactEM").fadeIn("slow");
popupStatusEM = 1;
}
}
//disabling popup with jQuery magic!
function disablePopupEM() {
//disables popup only if it is enabled
if (popupStatusEM == 1) {
$("#backgroundPopupEM").fadeOut("slow");
$("#popupContactEM").fadeOut("slow");
popupStatusEM = 0;
}
}
//centering popup
function centerPopupEM() {
//request data for centering
var windowWidth = document.documentElement.clientWidth;
var windowHeight = document.documentElement.clientHeight;
var popupHeight = $("#popupContactEM").height();
var popupWidth = $("#popupContactEM").width();
//centering
$("#popupContactEM").css({
"position": "absolute",
"top": windowHeight / 2 - popupHeight / 2,
"left": windowWidth / 2 - popupWidth / 2
});
//only need force for IE6
$("#backgroundPopupEM").css({
"height": windowHeight
});
}
$("body").on('click', "#popupContactCloseEM", function (e) {
//e.preventDefault();
alert('popupContactCloseEM');
disablePopupEM();
});
$("body").on('click', "#backgroundPopupEM", function (e) {
//e.preventDefault();
alert('backgroundPopupEM');
disablePopupEM();
});
GridView的:
GridView:
弹出窗口(在任何编辑点击时
图标:
Popup (when clicked on any of the edit
icon:
我不知道为什么,但是当我在点击X
或周围弹出的背景下, disablePopupEM
功能不叫关闭它。我甚至增加了一个测试警报
,我没有看到,无论是。
I am not sure why but when I click on the x
or the background around the popup, the disablePopupEM
function is not called to close it. I even added a test alert
and I am not seeing that either.
请帮我解决这个问题。
推荐答案
对于我来说这听起来非常相似,这一点:你分配单击处理程序
到元素
这还不存在,因为 DOM
未完成加载,但(如的JavaScript
之前初始化你的 HTML
)。
For me that sounds very similar to this: You assign click handlers
to elements
which do not yet exist because the DOM
did not finish loading yet (e.g. the JavaScript
is initialized before your HTML
).
我想尝试附加单击处理程序
的 $(文件)。就绪()内
funtion,这将被调用一次 DOM
满载 - 那么元素
可用,他们将与你的<$连接C $ C>处理程序。
I would try to attach the click handlers
inside the $(document).ready()
funtion, which will be called once the DOM
is fully loaded - then the elements
are available and they will be attached with your handler
.
$(document).ready(function() {
$("body").on('click', "#popupContactCloseEM", function (e) {
//e.preventDefault();
alert('popupContactCloseEM');
disablePopupEM();
});
$("body").on('click', "#backgroundPopupEM", function (e) {
//e.preventDefault();
alert('backgroundPopupEM');
disablePopupEM();
});
});
正如你所见,你只需要通过将其包围就绪
功能。
这篇关于为什么从UpdatePanel内打开时不会弹出关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!