有人可以告诉我我做错了什么,我无法解决这个问题,而且我已经阅读了10多个堆栈溢出范围问题,而且我非常困惑。
我的popup.js文件:
function popupClickGlobal()
{
window.popupClick = function(){
window.alert("insidePopupClick!!!!");
loading(); // loading
setTimeout(function(){ // then show popup, deley in .5 second
loadPopup(); // function show popup
}, 500); // .5 second
}
}
$("a.topopup").click(function() {
loading(); // loading
setTimeout(function(){ // then show popup, deley in .5 second
loadPopup(); // function show popup
}, 500); // .5 second
return false;
});
/* event for close the popup */
$("div.close").hover(
function() {
$('span.ecs_tooltip').show();
},
function () {
$('span.ecs_tooltip').hide();
}
);
$("div.close").click(function() {
disablePopup(); // function close pop up
});
$(this).keyup(function(event) {
if (event.which == 27) { // 27 is 'Ecs' in the keyboard
disablePopup(); // function close pop up
}
});
$("div#backgroundPopup").click(function() {
disablePopup(); // function close pop up
});
/************** start: functions. **************/
function loading() {
$("div.loader").show();
}
function closeloading() {
$("div.loader").fadeOut('normal');
}
var popupStatus = 0; // set value
function loadPopup() {
if(popupStatus == 0) { // if value is 0, show popup
closeloading(); // fadeout loading
$("#toPopup").fadeIn(0500); // fadein popup div
$("#backgroundPopup").css("opacity", "0.7"); // css opacity, supports IE7, IE8
$("#backgroundPopup").fadeIn(0001);
popupStatus = 1; // and set value to 1
}
}
function disablePopup() {
if(popupStatus == 1) { // if value is 1, close popup
$("#toPopup").fadeOut("normal");
$("#backgroundPopup").fadeOut("normal");
popupStatus = 0; // and set value to 0
}
}
/************** end: functions. **************/
我的index.php片段:
<script type="text/javascript" src="_script/popup.js"></script>
<script>
if(formPosted) {
window.alert("popupclick!");
$(document).ready(popupClickGlobal);
popupClickGlobal();
}
</script>
窗口显示我pupupclick!警告,我很困惑如何调用全局变量(似乎无处可去。我也尝试过$ .popupClickGlobal();来调用它。我期待第二次警报的警报后说内部的PopopClick! !!!
请帮助,谢谢。 克里斯
答案 0 :(得分:1)
popupClickGlobal
不是全局变量..它是声明它的dom ready处理程序的本地变量。
由于函数popupClickGlobal
将在全局范围内使用,只需删除它周围的jQuery(function(){...})
包装器
function popupClickGlobal() {
window.popupClick = function () {
window.alert("insidePopupClick!!!!");
loading(); // loading
setTimeout(function () { // then show popup, deley in .5 second
loadPopup(); // function show popup
}, 500); // .5 second
}
}
答案 1 :(得分:0)
尝试仅在popup.js
中添加以下代码function popupClickGlobal()
{
window.popupClick = function(){
window.alert("insidePopupClick!!!!");
loading(); // loading
setTimeout(function(){ // then show popup, deley in .5 second
loadPopup(); // function show popup
}, 500); // .5 second
}
}