[英]Trigger click event without link
I am working with one jQuery library that allows to open modal windows by clicking a link. 我正在使用一个jQuery库,该库允许通过单击链接打开模式窗口。 The point is that I want to open the window but without clicking any link.
关键是我要打开窗口,但不单击任何链接。 I know it's a little strange, but it is possible to call the modal without having the trigger link (where the reference to the modal library is) ?
我知道这有点奇怪,但是可以在没有触发器链接的情况下调用模式(模态库的引用在哪里) ?
Update: What I have tested 更新:我测试过的
<script type="text/javascript">
$(function() {
$('a[rel*=leanModal]').leanModal({ top : 100, closeButton: ".modal_close"});
});
</script>
...
<!-- a rel="leanModal" href="#modal" name="modal">Link</a -->
...
<script type="text/javascript">
$('#modal').click();
</script>
<div id="modal">
</div>
The reference to the modal div is in link, but I don't have that link and it won't be created. 对模式div的引用在链接中,但我没有该链接,也不会创建它。
Reference: leanModal.js 参考: leanModal.js
Just trigger the link click where you want. 只需在所需位置触发链接单击即可。
$(".myLink").trigger('click'); // or:
$(".myLink").click();
Edit: In your question you're using the wrong handler. 编辑:在您的问题中,您使用的是错误的处理程序。
$("modal")
would look for a <modal>
element. $("modal")
将查找<modal>
元素。 You're looking for $('#modal')
. 您正在寻找
$('#modal')
。
If you want to have the dialog pop up without a link at all, you should be able to set it hidden using display: none
in the CSS or style attribute, and then trigger it via code anyways. 如果您希望对话框完全不带链接地弹出,则应该能够使用
display: none
设置它为隐藏display: none
CSS或style属性中display: none
,然后无论如何都可以通过代码触发它。
Or, you can use Fancybox for added flexibility, and they're more open about how to use their dialog boxes without attaching to a specific link, but rather any element and decide what goes inside and how to trigger it. 或者,您可以使用Fancybox来增加灵活性,并且他们对如何使用对话框而不附加到特定链接(而不是附加到任何元素,并决定其中的内容以及如何触发它)更加开放。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.