jQuery Tools警报只能运行一次(但只能运行一次) [英] jQuery Tools alert works once (but only once)
问题描述
我正在尝试使用jQuery Tools构建简单的警报机制-响应一些Javascript代码,弹出带有消息的覆盖层,并单击OK按钮,单击该按钮可使覆盖层消失.琐碎的,还是应该的.我一直忙于关注 http://flowplayer.org/tools/demos/overlay/trigger .html ,并具有在第一次调用时可以正常运行的功能,但仅限于此时间.如果我重复执行应该暴露叠加层的JS动作,则不会.
I'm trying to build a simple alert mechanism with jQuery Tools -- in response to a bit of Javascript code, pop up an overlay with a message and an OK button that, when clicked, makes the overlay go away. Trivial, or it should be. I've been slavishly following http://flowplayer.org/tools/demos/overlay/trigger.html, and have something that works fine the first time it's invoked, but only that time. If I repeat the JS action that should expose the overlay, it doesn't.
我的内容/DIV:
<div class='modal' id='the_alert'>
<div id='modal_content' class='modal_content'>
<h2>hi there</h2>
this is the body
<p>
<button class='close'>OK</button>
</p>
</div>
<div id='modal_background' class='modal_background'><img src='/images/overlay/f9f9f9-180.png' class='stretch' alt='' /></div>
</div>
和Javascript:
and the Javascript:
function showOverlayDialog() {
$('#the_alert').overlay({
mask: {color: '#cccccc', loadSpeed: 200, opacity: 0.9},
closeOnClick: false,
load: true
});
}
正如我所说:第一次调用showOverlayDialog()时,覆盖层将按应有的方式显示,并在单击确定"按钮时消失.但是,如果我使showOverlayDialog()再次运行,而不重新加载页面,则什么也没有发生.如果我重新加载页面,则该模式会重复-第一次调用调出叠加层,而第二次调用则不叠加.
As I said: When showOverlayDialog() is invoked the first time, the overlay appears just like it should, and goes away when the "OK" button is clicked. But if I cause showOverlayDialog() to run again, without reloading the page, nothing happens. If I reload the page, then the pattern repeats -- the first invocation brings up the overlay, but the second one doesn't.
我显然缺少了一些东西-那里有什么建议吗?谢谢!
I'm obviously missing something -- any advice out there? Thanks!
推荐答案
定义对话框并将load
设置为false(禁用对话框的自动加载):
Define the dialog and set load
to false (disabling auto-load of the dialog):
$('#the_alert').overlay({
mask: {
color: '#cccccc',
loadSpeed: 200,
opacity: 0.9
},
closeOnClick: false,
load: false
});
然后在显示对话框的处理程序中,调用load
api方法:>
Then in your handler that shows the dialog, call the load
api method:
$("#show").click(function() {
$("#the_alert").data("overlay").load();
});
(将点击事件分配给ID为show
的元素,该元素显示叠加层)
(Assigns a click event to an element with id of show
which shows the overlay)
此处的工作示例: http://jsfiddle.net/andrewwhitaker/Vqqe6/
我认为您不能在一个特定的元素上定义多个叠加层,这导致了您的问题.
I don't believe you're able to define more than one overlay on a particular element, which was causing your problem.
这篇关于jQuery Tools警报只能运行一次(但只能运行一次)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!