Bra*_*son 11 javascript jquery if-statement
我正在使用leanModal http://leanmodal.finelysliced.com.au需要启动它来打开div但没有.click()方法.基本上我正试图这样做..
if(cartItems === 0){
$("#cartEmpty").leanModal(); // #cartEmpty is my div with the message that needs to be initiated.
} else {
$("#nextStep").leanModal(); // #nextStep is my div is the form
}
Run Code Online (Sandbox Code Playgroud)
关于这个的任何想法?
Dan*_*n F 19
我通过源代码戳了一下leanmodal,看起来你不能.你仍然需要一个触发它的链接.但是,您应该可以执行以下未经测试的顶级代码
添加几个不可见的链接.内联样式是一件坏事,只是内联简化
<a href="#cartEmpty" id="showCartEmpty" style="display:none" rel="leanModal" name="cartEmpty">empty cart</a>
<a href="#nextStep" id="showNextStep" style="display:none" rel="leanModal" name="nextStep">next step</a>
Run Code Online (Sandbox Code Playgroud)
为leanmodal进行正常设置
$(function() {
$('a[rel*=leanModal]').leanModal();
});
Run Code Online (Sandbox Code Playgroud)
在虚拟不可见链接上调用click方法
if(cartItems === 0){
$("#showCartEmpty").click(); // in theory this'll cause the modal to be shown
} else {
$("#showNextStep").click(); // in theory this'll cause the modal to be shown
}
Run Code Online (Sandbox Code Playgroud)
如果失败了,源代码非常小,你应该能够将它与自己的项目纠缠在一起,并将其修改为可以在要模拟的东西上调用,而不是启动模态的东西.