点击模拟故障

时间:2014-10-11 19:47:34

标签: jquery jquery-selectors onclick greasemonkey

我正在尝试为livejournal写一些注释扩展器(作为greasemonkey脚本),并且在扩展链接上遇到点击模拟:

<div style='margin-top: 3px; font-size: smaller'>
 (<a href="http://unique page url" rel="nofollow">Reply</a>) 
 (<a href='page url'>Parent</a>) 
 (<a href='http://unique page url'>Thread</a>) 
 <span id='expand_*'>(<a href='http://unique page url' onclick="ExpanderEx.make(event,this,'http://unique page url','*',true)">Expand</a>)</span>
    <div class="quickreply" id="ljqrt*" style="display: none;"></div>
</div>

我尝试使用此代码激活页面上的所有链接,但失败了:

$(document).ready(function() {
  $('a').each(function() {
   $(this).[0].click();
  });
});

任何帮助都会非常感激,因为我完全是jquery的新手。

UPD。 我修改脚本,所以它看起来像这样:

jQuery(document).ready(function() { 
 console.log("function execute"); 
 $('[id^="expand_"] a').click(); 
 console.log("function Log");
 console.log($()); 
}); 

执行后firebug中的控制台输出是:

function execute  --- lj_expa...user.js (line 10) 
TypeError: $(...) is null --- lj_expa...user.js (line 11) 
Server did not return the new auth_token, further request may fail Error: Permission denied to access property 'toString' --- ??.ljli...3140103 (line 1372)

UPD。添加以下行解决了我的问题,两个选择器都正常工作!

// @require http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js

1 个答案:

答案 0 :(得分:0)

基于以下结构的扩展链接:

<span id="expand_34400795"> <a href="http://*.livejournal.com/1021211.html?thread=34400795#t34400795" onclick="ExpanderEx.make(event,this,'http://*.livejournal.com/1021211.html?threa??d=34400795#t34400795','34400795',true)">Expand</a></span>

尝试:

$(document).ready(function() {
    $('[id^="expand_"] a').click();
});

用简单的英语,这个jQuery语句读取find all <a> elements in <span>s with ids starting 'expand_', then click the links

相关问题