繁体   English   中英

需要jQuery通过单击其他div来激活点击

[英]Need jquery to activate a click through by clicking on a different div

我希望有人可以提供帮助...我是Jquery的新手....我想要实现的是单击超链接图像,但这是在单击页面另一部分上完全独立的div而不是单击比我刚才提到的超链接图像好。 .......超链接的图像也必须不可见。 万一有人想知道为什么我需要这个....这是因为我想要自己的自定义按钮,而不是我正在使用的CMS附带的标准按钮,因此无法更改....基本上,这是一个解决系统所有者的建议。

这是我认为可行的

<style>

  #my-custom-button{
     margin: 0 auto;
     width: 200px     
   }


  #the-standard-button{
     display : none
   }    

</style>


<div id="my-custom-button">
    <a href="#"><img src="../images/order-now.png"></a>
</div>

 <div id="the-standard-button"> 
     <?php
         proprietary PHP here that renders the standard button
     ?>
 </div>


 <script type="text/javascript">
  <!--
    $(function(){
       $("#my-custom-button").click(function(){
         $("#the-standard-button").click();
       });
    });
  -->
 </script>

整体

<?php propiertary blah blah ?>

使其难以解读,但我的猜测是,无论是php生成的任何内容,都将生成处理程序,即php生成

<button id="phpButton">
    blah
</button>

然后像

$("#phpButton").click(....)

请注意,处理程序不在“#the-standard-button”上。 因此,您需要确保在调用$(“#my-custom-button”)中的click()时使用正确的选择器。click(...)

看看这个jsFiddle 请注意触发了哪个次要点击事件。

我不确定我是否完全理解您的问题,如果您想要的是,当您单击一个按钮时,它的作用就像单击另一个按钮一样。

如果默认按钮也是锚标记( <a> ),则此解决方案将起作用

HTML:

<div id="newButton">
<a href="#"><img src="/theimage.jpg"/></a>
</div>

<div id="oldDiv">
<a href="whatever.com"><img src"oldImage.png"/></a>
</div>

JQuery的:

jQuery(document).ready(function($){
    $("#oldDiv").hide();
    $("#newDiv > a").click(function(){
        window.location = $("#oldDiv>a").attr("href");
    });
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM