我的html中有一个jquery覆盖窗口,旁边有一个按钮,可以在这里激活代码。
<!-- Validation Overlay Box -->
<div class="modal" id="yesno" style="top: 100px; left: 320px; position: relative; display: none; z-index: 0; margin-top: 100px;">
<h2> Authentication Failed</h2>
<p style="font-family:Arial; font-size:small; text-align:center">
Ether your username or password has been entered incorrectly.
Please make sure that your username or password entered correctly...
</p>
<!-- yes/no buttons -->
<p align="center">
<button class="close"> OK </button>
</p>
</div>
<SCRIPT>
$(document).ready(function() {
var triggers = $(".modalInput").overlay({
// some mask tweaks suitable for modal dialogs
mask: {
color: '#a2a2a2',
loadSpeed: 200,
opacity: 0.9
},
closeOnClick: false
});
var buttons = $("#yesno button").click(function(e) {
// get user input
var yes = buttons.index(this) === 0;
// do something with the answer
triggers.eq(0).html("You clicked " + (yes ? "yes" : "no"));
});
$("#prompt form").submit(function(e) {
// close the overlay
triggers.eq(1).overlay().close();
// get user input
var input = $("input", this).val();
// do something with the answer
triggers.eq(1).html(input);
// do not submit the form
return e.preventDefault();
});
});
</SCRIPT>
"<BUTTON class="modalInput" rel="#yesno">You clicked no</BUTTON>"
我想要的只是我不想在点击按钮或通过链接显示叠加层。是否可以通过像“showOverlay()”这样的javascript函数调用它?
答案 0 :(得分:2)
您有2个选项,可以使用load
option,如下所示:
var triggers = $(".modalInput").overlay({
mask: {
color: '#a2a2a2',
loadSpeed: 200,
opacity: 0.9
},
closeOnClick: false,
load: true
});
这使它立即打开,you can see the API demo here。如果你想要的是在设置之后的某个时刻显示叠加层,只需触发它绑定的事件click
,如下所示:
$(".modalInput").click();
这会触发与实际单击按钮或链接相同的处理程序行为,打开覆盖图。