如何在jquery中单击一个单击另一个的东西?

时间:2016-02-04 10:57:44

标签: javascript jquery

我试图设置一些javascript来检测点击事件标题的时间以及点击它的时间点击另一个链接,如果这是有道理的。

刚才意识到必须点击事件卡本身的链接。

Frontend

这是我的代码:

var eventTitle = $(".eventCardCnt .title");
var eventMoreInfo = $(".custom_button").find("a");

    eventTitle.click( function(){
       eventMoreInfo.trigger("click");
        //console.log("title clicked");
    });

html:

        <div class="eventCardCnt eventDisplayCnt  isAnEvent" >
        <div class="cntHolder" >
        <div class="details">
        //  When this is clicked.
        <span class="title">Understanding ‘Prevent Duty’ & Radicalisation</span>
        <div class="dateDetails" style="color:#999999; font-size:14px; line-height:120%;font-weight:normal; padding:3px 0px; padding-bottom:0px;text-align:left; margin-bottom:5px; margin-top:0px; border-bottom:0px solid #EEEEEE;">
        <div class="dateCnt">
        <div class="dates">
        <div class="dateWrap">
        <div class="date">Wednesday 10 February 2016</div>
        <div class="time">9:30 am</div>
        </div>
        </div>
        </div>
        </div>
        <span class="location"><a href="http://maps.google.com/?q=Holiday+Inn,+Camden+Lock,+London" target="_blank">Holiday Inn, Camden Lock, London</a></span>
        <div class="eventDetails">
        <div class="price" >£250.00</div>
        <div class='custom_button'>
        <div class="more_info_button">
        //  Click this link
        <a href="http://carleyconsult.wp.castus1.co.uk/product/understanding-prevent-duty-radicalisation/">More info and book</a>
        </div>
        </div>
        </div>
        </div>
        </div>
        </div>

任何想法都将不胜感激。

2 个答案:

答案 0 :(得分:0)

您可以在标题点击事件中使用点击事件,例如 $(“。link”)。click();

$(".header").click(function(){
    $(".link").click();
});
$(".link").click(function(){
    alert("Another link Clicked");
});

答案 1 :(得分:0)

尝试此代码 HTML PAGE

<div class="eventCardCnt eventDisplayCnt  isAnEvent" >
        <div class="cntHolder" >
        <div class="details">
        //  When this is clicked.
        <span class="title" onclick="clickhref()" >Understanding ‘Prevent Duty’ & Radicalisation</span>
        <div class="dateDetails" style="color:#999999; font-size:14px; line-height:120%;font-weight:normal; padding:3px 0px; padding-bottom:0px;text-align:left; margin-bottom:5px; margin-top:0px; border-bottom:0px solid #EEEEEE;">
        <div class="dateCnt">
        <div class="dates">
        <div class="dateWrap">
        <div class="date">Wednesday 10 February 2016</div>
        <div class="time">9:30 am</div>
        </div>
        </div>
        </div>
        </div>
        <span class="location"><a href="http://maps.google.com/?q=Holiday+Inn,+Camden+Lock,+London" target="_blank">Holiday Inn, Camden Lock, London</a></span>
        <div class="eventDetails">
        <div class="price" >£250.00</div>
        <div class='custom_button'>
        <div class="more_info_button">
        //  Click this link
        <a id="aclick" href="http://carleyconsult.wp.castus1.co.uk/product/understanding-prevent-duty-radicalisation/">More info and book</a>
        </div>
        </div>
        </div>
        </div>
        </div>
        </div>

<强> JAVASCRIPT

function clickhref()
{
     $("#aclick").click();
}