gpt4 book ai didi

javascript - 触发 Div 点击链接

转载 作者:行者123 更新时间:2023-11-29 16:29:00 25 4
gpt4 key购买 nike

我有一个网站 http://www.thebalancedbody.ca/左侧有一个弹出的联系表单(联系方式),其 ID 为 <div id="mycontactform"> .

页脚中还有一个名为“联系我们”的链接

<a href="#"  title="CONTACT US">CONTACT US</a>

我需要此链接来触发弹出的联系表单,就像手动单击联系选项卡一样。

这可能吗?我该怎么做?

谢谢

乔纳森

最佳答案

所有建议的解决方案都应该有效。但我认为你需要阻止 anchor 的默认操作。

将此代码添加到文档 部分的 <script> 标记内。

$(document).ready(function(){
$("#contact").click(function(event){
event.preventDefault(); //stops the browser from following the link
$("#contactable").click(); //opens contact form
alert("Showing mycontactform"); //remove this when it's working
});
});

您需要将“id”标签添加到您的联系人 anchor :

<a href="#" id="contact" title="Contact Us">CONTACT US</a>

您还需要确保在文档的 部分中包含 jQuery。

在 标记后添加此行:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"></script>

关于javascript - 触发 Div 点击链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2522600/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com