点击一个元素触发点击另一个元素[JQuery]
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21662734/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Click on an element triggers the click on another element [JQuery]
提问by Fabio
I have a top menu with the buttons home
, prodotti
, info
and contatti
. Below there is an accordion menu that has always an open slide and when you click on a title it changes and opens the relative slide.
我与按钮的顶部菜单home
,prodotti
,info
和contatti
。下面是一个手风琴菜单,它总是有一个打开的幻灯片,当您单击标题时,它会更改并打开相关幻灯片。
I would like that when I press for example on contatti
in the top menu it triggers the click on contattaci
in the accordion menu so that the relative slide opens as if i clicked directly on contattaci
(using JQuery).
我希望当我contatti
在顶部菜单中按下例如时,它会触发contattaci
手风琴菜单中的点击,以便相关幻灯片打开,就像我直接点击一样contattaci
(使用 JQuery)。
The HTML of the top menu looks like this:
顶部菜单的 HTML 如下所示:
<div id='cssmenu'>
<ul>
<li id="home" class='active'><span>Home</span></li>
<li id="prodotti"><span>Prodotti</span></li>
<li id="info"><span>Info</span></li>
<li id="contact" class='last'><span>Contatti</span></li>
</ul>
</div>
The HTML of the accordion menu looks like this:
手风琴菜单的 HTML 如下所示:
<div class="container">
<div id="demo">
<ol>
...................
<li id="contattaci">
<h2><span>Contattaci</span></h2>
<div>
<iframe src="form.php"width="625px" height="400px" ></iframe>
</div>
<p class="ap-caption">e-mail</p>
</li>
......
</ol>
</div>
<div>
So when I click on the contatti
item of the top menu (with id="contact
") I would like to simulate a click on "contattaci
" in the accordion menu (with id="contattaci
") so that a slide with a contact form opens next to "contattaci
".
所以,当我在点击contatti
顶部菜单项(使用id =“ contact
‘),我想模拟一个点击’contattaci
手风琴菜单‘(使用id =’ contattaci
”),以便与联系人形式的幻灯片旁边打开“ contattaci
”。
I'm not sure that it is possible, anyway I tried using this JQuery code:
我不确定这是否可能,无论如何我尝试使用此 JQuery 代码:
<script>
$(document).on('click', '#contact', function() {
$("#contattaci").click();
});
</script>
This doesn't work. I hope you can help me to fix the problem.
这不起作用。我希望你能帮我解决这个问题。
EDIT: The css accordion menu uses css3 but also a jquery library called jquery.accordionpro.min.js that makes use of JQuery Swipe library (https://github.com/jgarber623/jquery-swipe). Probably the slide can be opened using a function in Jquery Swipe library. What do you think? If you can help let me know.
编辑:css 手风琴菜单使用 css3,但还有一个名为 jquery.accordionpro.min.js 的 jquery 库,它利用了 JQuery Swipe 库 ( https://github.com/jgarber623/jquery-swipe)。可能可以使用 Jquery Swipe 库中的函数打开幻灯片。你怎么认为?如果你能帮忙告诉我。
Linkto the website for further analysis: http://tinyurl.com/m2u5t7d
链接到网站进行进一步分析:http: //tinyurl.com/m2u5t7d
回答by pschueller
I would try it this way:
我会这样尝试:
$(document).on('click', '#contact', function(event) {
event.preventDefault();
$("#contattaci h2").click();
});
回答by Pramod Kharade
$(document).on('click', '#contact', function(e) {
$("#contattaci").trigger('click');
});
回答by kwyjibear
I know I'm a little late to the party but...For the inner click
我知道我参加聚会有点晚了但是......对于内部点击
$("#contattaci h2").click();
change it to
将其更改为
$("#contattaci h2").trigger("click");