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

时间:2014-05-16 06:02:47

标签: javascript jquery html css addthis

我有以下代码

<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 -->

在此我希望当我点击Refer your friends时,它会触发addthis_button_email addthis_button_preferred_3 at300b&amp;它会显示一个弹出窗口。

我试过下面的代码

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

好吧,现在它是如何触发的。

实际上是一个项目清单。我只展示了一件商品。因此,每次如果我点击它需要最后一项属性。我们可以从列表中正确选择一个项目。我们怎么能这样做?

3 个答案:

答案 0 :(得分:2)

您缺少类选择器[dot]并删除选择器之间的空格:

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

答案 1 :(得分:2)

你错过了班级选择器(即点),所以放置它并使用下面的代码

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

有关.trigger()的详情,请参阅this

答案 2 :(得分:1)

我认为您正在寻找的功能是“trigger()”(http://api.jquery.com/trigger/

它可用于触发所选元素上的事件。

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