为什么从 div 填充新窗口会删除原始文档中的 div?
最近几天,我在使用 Prototype 填充窗口(可调整大小的可拖动原型-UI 窗口) 内容时遇到了一个大问题。 我终于找到了一个我想要做的工作示例,但它使用某种“Windows插件”作为原型,我不使用它,所以基本上我只是想问如何编译他们的代码以适应正常的原型。
我想做的是有一个窗口,其中的内容是从正文中的 DIV 中提取的,问题是在我打开窗口一次后 - div 被删除,我无法重新打开窗口。
这是他们的工作代码:
if (contentWin != null) {
Dialog.alert("Close the window 'Test' before opening it again!",{width:200, height:130});
}
else {
contentWin = new Window({maximizable: false, resizable: false, hideEffect:Element.hide, showEffect:Element.show, minWidth: 10, destroyOnClose: true})
contentWin.setContent('test_content', true, true)
contentWin.show();
// Set up a windows observer, check ou debug window to get messages
myObserver = {
onDestroy: function(eventName, win) {
if (win == contentWin) {
$('container').appendChild($('test_content'));
contentWin = null;
Windows.removeObserver(this);
}
debug(eventName + " on " + win.getId())
}
}
Windows.addObserver(myObserver);
}
这是我的代码(每次刷新我不能多次打开它):
function openCappAR() {
var cApp = new UI.Window({theme: "ultra_dark",
width: 360,
height: 350,
superflousEffects: superflousEffects}).center().show();
cApp.setContent(
$('ceBlock').setStyle({
display: 'inherit'
})
)
cApp.header.update("Create an App");
}
基本上我需要 DIV 在窗口关闭时返回到他的第一个版本。 我认为 Javascript 也有观察者,所以如果我错了,我会添加一个 JS 标签来修复我:)
编辑:基本上我需要的是一个窗口,我可以在关闭它后重新打开它,主要现在的问题是,当我打开一个新窗口时,它会从原始文档中删除 div,而当我关闭窗口时,根本没有 DIV。
I'm having a big problem the last days with filling in the window (Resizeable-Draggable Prototype-UI window) content with Prototype.
I have finally found a working example of what I'm trying to do but it uses some kind of "Windows Plugin" for prototype which i don't use so basically i just want to ask how to compile their code to fit the normal prototype.
What I'm trying to do is to have a window with content pulled from a DIV in the body and the problem is that after i open the window once - The div is deleted and i can't re-open the window.
Here is their working code:
if (contentWin != null) {
Dialog.alert("Close the window 'Test' before opening it again!",{width:200, height:130});
}
else {
contentWin = new Window({maximizable: false, resizable: false, hideEffect:Element.hide, showEffect:Element.show, minWidth: 10, destroyOnClose: true})
contentWin.setContent('test_content', true, true)
contentWin.show();
// Set up a windows observer, check ou debug window to get messages
myObserver = {
onDestroy: function(eventName, win) {
if (win == contentWin) {
$('container').appendChild($('test_content'));
contentWin = null;
Windows.removeObserver(this);
}
debug(eventName + " on " + win.getId())
}
}
Windows.addObserver(myObserver);
}
Here is the one i have (I can't open it more than once per refresh):
function openCappAR() {
var cApp = new UI.Window({theme: "ultra_dark",
width: 360,
height: 350,
superflousEffects: superflousEffects}).center().show();
cApp.setContent(
$('ceBlock').setStyle({
display: 'inherit'
})
)
cApp.header.update("Create an App");
}
Basically i need the DIV to get back to his first version when the window is closed.
I think that Javascript have Observers too so ill add a JS tag if I'm wrong fix me :)
EDIT: Basically what i need is a window that i will be able to re-open after i close it, the main problem now is when i open a new window it removes the div from the the original document and when i close the window there is NO DIV at all.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查找 Prototype UI 后,我意识到您并不是在谈论打开一个真实窗口,而是在页面上打开一个可移动的类似窗口的元素。这是相当重要的一点。
不管怎样,如果我理解你的问题(我不确定我理解了),我想你可以克隆 div 元素,并在窗口中使用克隆。这将使原始 div 保持不变并仍然存在。
还没有测试过,但应该可以。请注意,
clone
不会克隆或复制元素上的任何事件侦听器,因此您必须再次添加这些侦听器(如果有)。编辑: Prototype 的
clone
方法 主要只是一个别名浏览器内置的cloneNode
方法。因此,如果你不能使用 Prototype 的方法,你应该可以这样做:After looking up Prototype UI I realized that you're not talking about opening an real window, but rather a moveable window-like element on the page. That's rather important to note.
Anyway, if I understood your question (and I'm not sure I did), I'd imagine that you can just clone the div element, and use the clone in the window. That would leave the original div untouched and still in place.
Haven't tested it, but it should work. Just note, that
clone
doesn't clone or copy any event listeners you have on the element, so you'll have to add those again, if you have any.Edit: Prototype's
clone
method is mostly just an alias for the browser's built-incloneNode
method. So if you can't use Prototype's method, you should be able to do this instead: