我有以下代码
<div class="event_starpline">
<div style="width:71%;float:left;">
<div id="starpline_timestamp_location"
title="Location : Chennai">Chennai</div>
<div id="starpline_timestamp_posted"
title="Posted 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&tmr=load%3D1400219036211%26core%3D1400219036863%26main%3D1400219038575%26ifr%3D1400219038590&cb=0&cdn=0&chr=UTF-8&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&ab=-&dh=10.0.1.22&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&du=http%3A%2F%2F10.0.1.22%2Ffirstplanet%2Ffpin%2Fdev%2Fpg%2Fad%2Fall%2F&dt=First%20Planet%3A%20Job%20posts&dbg=0&md=0&cap=tc%3D0%26ab%3D1&inst=1&vcl=1&jsl=1&prod=undefined&lng=en-US&ogt=&pc=men&pub=ra-510b54196b4318c8&ssl=0&sid=5375a59c9ed1ff23&srpl=1&srcs=1&srd=1&srf=1&srx=1&ver=300&xck=0&xtr=0&og=&aa=0&csi=undefined&rev=1399981304&ct=1&xld=1&xd=1&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;
});
好吧,现在它是如何触发的。
实际上是一个项目清单。我只展示了一件商品。因此,每次如果我点击它需要最后一项属性。我们可以从列表中正确选择一个项目。我们怎么能这样做?
答案 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;
});