1
對不起,簡單的問題。 我不確定是否所有這些都很重要,但我會提及它以防萬一。 :當用戶點擊一個鏈接,這是發生了什麼:我不知道如何關閉一個簡單的彈出框
function begin(some info) is called->Makes an Ajax request to backend PHP->
PHP calls the callback function->Callback function calls another JS function that creates a popup->
In the popup creating function, The Save button is assigned a function that makes an ajax request and sends PHP some user input.->
PHP makes a callback to another function that does nothing.
在這裏,這是一個拼彈出框的功能。
function collection(name, description, data){
var json = data;
var cont = openSitePopup("400","300");
//We create div objects.
var namecell = ce("div","sitePopupCell");
//Stuff
// We create a button and assign the createProducts Method to it.
var sbtbutton = createBtn("submitObject","SAVE","createProducts()");
//We append all the div objects to the popup.
cont.appendChild(namecell);
//..
}
function openSitePopup(width,height) {
//try to center the popup if values are not passed
var xPos = (getWinWidth()/2) - (width/2) + sl;
var yPos = (getWinHeight()/2) - (height/2) + st;
sitepopupwin = ge("sitePopupWin");
clearElement(sitepopupwin);
var winhandle = ce("div","","sitePopupHandle");
sitepopupwin.style.display = "block";
//Other style assignments.
//closebutton
var close = ce("img","sitePopupCloseBtn");
close.setAttribute("src",theme_path + "/images/icons/close.png");
//start adding goodies
var mydiv = ce("div","sitePopupContainer");
winhandle.appendChild(close);
winhandle.appendChild(createCleaner());
sitepopupwin.appendChild(winhandle);
sitepopupwin.appendChild(mydiv);
//return reference to the container for adding stuff
return mydiv;
}
function createProducts()
{
//Some exciting Ajax stuff with a callback to writeNewFolder()
}
function writeNewFolder(data){
//Nothing of interest here...yet.
}
現在,當我按在彈出的Save
按鈕,請求被成功地進行,但彈出不會關閉。我知道Window.Close()
函數,但它不起作用。 cont.Close()
似乎是一個明顯的選擇,但在這種情況下,我得到這個錯誤:Uncaught TypeError: Object #<HTMLDivElement> has no method 'Close'
因此,Cont只是一個div元素。 openSitePopup()
方法只返回一個div。
感謝您的幫助。
編輯:
function ce(elementType,elementClass,elementId,txt) {
var e = document.createElement(elementType);
//add optional parameters
if (elementId) e.setAttribute("id",elementId);
if (elementClass) setClass(e,elementClass);
//append extra text. If passed an object, append with without the textnode wrapper
if (isData(txt)) {
if (typeof(txt)=="object") e.appendChild(txt);
else e.appendChild(ctnode(txt));
}
return e;
}
希望的原創者不介意我張貼了他的一些代碼在這裏。那麼,它是免費的,開源的,所以它應該沒問題......我想。
編輯2:ge
功能。這個很簡單。
function ge(element) {
return document.getElementById(element);
}
我的歉意!我認爲'ce'是一個標準的JavaScript函數。它基本上創建一個元素。我會加入它。 – zermy 2011-12-19 18:23:54
查看更新..... – mplungjan 2011-12-19 18:49:39
您的解決方案奏效,非常感謝。你是對的,它不是一個窗口元素,只是一個div。多麼有趣。 – zermy 2011-12-19 18:52:45