如何通过按钮的onclick事件调用href? [英] How to call a href by onclick event of a button?

查看:21
本文介绍了如何通过按钮的onclick事件调用href?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下 a href 我用来打开 jquery 对话框,效果很好.基本上openDialog类已经附上了jquery对话框代码:

I have the following a href I use to open jquery dialogs, which works fine. Basically, the openDialog class has attached the jquery dialog code:

 <a class='openDialog' data-dialog-id='myEditDlg' data-dialog-autosize='false' data-dialog-alt='580' data-dialog-larg='740' data-dialog-title='test dialog' href='/mycontroller/EditDlg/myid'></a>

现在,我想通过按钮的 onclick 事件来调用它.基本上,当我单击按钮时,我希望具有与单击的 <a class='openDialog' href 相同的行为.我该怎么做?**

Now, I'd like to call it by the onclick event of a button. Basically, I'd like to have the same behaviour of the clicked <a class='openDialog' href when I click a button. How can I do it?**

推荐答案

如果我回答你的问题,那么可能是 jQuery trigger()(?) 是你要找的.示例:

If I get you question right then may be jQuery trigger()(?) is what you are looking for. Example:

<button id="bt">Click</button>
<a href="example.com" id="ex">Triggerable link</a>

<script type="text/javascript">
  $('#bt').click(function() {
       $('#ex').click();
  });
</script>

这篇关于如何通过按钮的onclick事件调用href?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆