简体   繁体   English

触发共享按钮,单击另一个按钮

[英]Trigger the share button click on clicking another button

I have the following code 我有以下代码

<div class="event_starpline">
    <div style="width:71%;float:left;">
        <div id="starpline_timestamp_location" 
             title="Location&nbsp;: Chennai">Chennai</div>
        <div id="starpline_timestamp_posted" 
             title="Posted &nbsp;Jan 30, 2013" 
             style="margin-left:10px;"> 
            <acronym title="30 January 2013 @ 8:58am">471 days ago</acronym>
        </div>
        <div id="starpline_timestamp_refer" 
             title="Refer your friends" 
             style="margin-left:10px;"> 
            <a href="#">Refer your friends</a>
         </div>
    </div>
    <div class="starpline_right" style="width:28%;">
        <div style="float:left; width:108px; padding-top:5px;">
            <!-- AddThis Button BEGIN -->
            <div class="addthis_toolbox addthis_default_style addthis_20x20_style" 
                addthis:url="http://10.0.1.22/firstplanet/fpin/dev/pg/ad/read/39342/community-developer-4" 
                addthis:title="Community developer 4" 
                addthis:description="Job" description=""> 
                    <a class="addthis_button_twitter addthis_button_preferred_2 at300b" 
                       title="Tweet" href="#">
                        <span class=" at300bs at15nc at15t_twitter">
                            <span class="at_a11y">Share on twitter</span>
                        </span>
                    </a>
                    <a class="addthis_button_facebook addthis_button_preferred_1 at300b" title="Facebook" href="#">
                        <span class=" at300bs at15nc at15t_facebook">
                            <span class="at_a11y">Share on facebook</span>
                        </span>
                    </a>
                    <a class="addthis_button_email addthis_button_preferred_3 at300b" 
                       target="_blank" title="Email" href="#">
                        <span class=" at300bs at15nc at15t_email">
                            <span class="at_a11y">Share on email</span>
                        </span>
                    </a>

                <div class="atclear"></div>
            </div>
            <script type="text/javascript">
                var addthis_config = {
                    "data_track_addressbar": true
                };
            </script>
            <script type="text/javascript" 
                    src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-510b54196b4318c8"></script>
            <div id="_atssh" 
                 style="visibility: hidden; height: 1px; width: 1px; position: absolute; z-index: 100000;">
                <iframe id="_atssh679" 
                        title="AddThis utility frame" 
                        src="//ct1.addthis.com/static/r07/sh158.html#iit=1400219038582&amp;tmr=load%3D1400219036211%26core%3D1400219036863%26main%3D1400219038575%26ifr%3D1400219038590&amp;cb=0&amp;cdn=0&amp;chr=UTF-8&amp;kw=open%20source%2Cfirst%20planet%2Cfirstplanet%2Cjob%20seekers%2Cunemployment%2Cfreshers%2Crecruitment%2Ctraining%2Cjobs%2Cinformation%20technology%2CIT%20Job%2Cwalkins%2Csatori%2Clamp%2Cdotnet%2Cjava%2Cchennai%2Canna%20salai%2Ctechnologies&amp;ab=-&amp;dh=10.0.1.22&amp;dr=http%3A%2F%2F10.0.1.22%2Ffirstplanet%2Ffpin%2Fdev%2Fpg%2Fsearch%2F%3Ftag%3Da%26entity_subtype%3Dad%26entity_type%3Dobject%26search_type%3Dentities&amp;du=http%3A%2F%2F10.0.1.22%2Ffirstplanet%2Ffpin%2Fdev%2Fpg%2Fad%2Fall%2F&amp;dt=First%20Planet%3A%20Job%20posts&amp;dbg=0&amp;md=0&amp;cap=tc%3D0%26ab%3D1&amp;inst=1&amp;vcl=1&amp;jsl=1&amp;prod=undefined&amp;lng=en-US&amp;ogt=&amp;pc=men&amp;pub=ra-510b54196b4318c8&amp;ssl=0&amp;sid=5375a59c9ed1ff23&amp;srpl=1&amp;srcs=1&amp;srd=1&amp;srf=1&amp;srx=1&amp;ver=300&amp;xck=0&amp;xtr=0&amp;og=&amp;aa=0&amp;csi=undefined&amp;rev=1399981304&amp;ct=1&amp;xld=1&amp;xd=1&amp;fcu=U3WlnIGSxBl" 
                        style="height: 1px; width: 1px; position: absolute; z-index: 100000; border: 0px; left: 0px; top: 0px;">
                </iframe>
            </div>
            <script type="text/javascript" 
                    src="http://ct1.addthis.com/static/r07/core131.js"></script>
            <!-- AddThis Button END -->

In this i want when i will click Refer your friends it will trigger addthis_button_email addthis_button_preferred_3 at300b & it will show a pop up. 在这种情况下,当我单击“推荐Refer your friends ,它将触发addthis_button_email addthis_button_preferred_3 at300b并显示一个弹出窗口。

I tried below code 我尝试下面的代码

jQuery("div#starpline_timestamp_refer").click(function(){
       // trigger second button 
       jQuery(".addthis_button_email addthis_button_preferred_3 at300b").click()
       return false;
    });

Okay some how its triggered now. 好的,现在它是如何触发的。

Actually its a list of items. 实际上是项目清单。 I have shown one item only. 我只显示了一项。 So every time if i click it takes last item property. 因此,每当我单击它时,它就需要最后一个属性。 Can we select properly one item from the list. 我们可以从列表中正确选择一项吗? How can we do that ? 我们该怎么做?

You are missing the class selector [dot] and remove the space between selector : 您缺少类选择器[dot]并删除选择器之间的空格:

jQuery(".addthis_button_email.addthis_button_preferred_3.at300b").click()
//                 here       ^^            and here      ^^

You have missed class selector( ie dot) so place it and use below code 您错过了类选择器(即点),因此将其放置并使用以下代码

jQuery(".addthis_button_email.addthis_button_preferred_3.at300b").trigger( "click" );

For more information on .trigger() please see this . 有关.trigger()更多信息,请参见this

I think the function you are looking for is "trigger()" ( http://api.jquery.com/trigger/ ) 我认为您正在寻找的功能是“ trigger()”( http://api.jquery.com/trigger/

It can be used to trigger events on a chosen element. 它可用于触发所选元素上的事件。

jQuery("div#starpline_timestamp_refer").click(function(){
       // trigger second button 
       jQuery(".addthis_button_email addthis_button_preferred_3 .at300b").trigger("click");
       return false;
    });

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

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