English 中文(简体)
利用javascript 点击无灌木的物品
原标题:Using javascript to click on item with no href

基本上,我使用“Landlugin”一词,我正试图书写一个文字,目的是在每一页上找到一个特定类别的图像并点击它。 如果该项目是“被点击”的,那么,由于这里的其他几个职位,有些是使用 anchor子,而如果假定没有耳光,那么,在图像或ton子上是否存在着“浮”的方法?

例如,我要通过调查来做我的工作,他们有几个检查箱或无线电台。 是否有办法用script子的文字选择 but子?

就此而言,这是我过去在一个有神父的纽州进行的“浮标”。

$("a.tip").each(function(){
if($(this).attr("caption")=="captionName"){
$.get("http://www.website.com" +$(this).attr("href"),window.location.reload());
return;
    }
});

* 就 gr骑师的能力而言,我无法确定它能够和能够做些什么。 diveintogreasemonkey.org似乎已不再是东道方,因此文件很难提交。

而且,这不同于点击听众,因为我想要用文字做点击。 您可能掌握的任何参考材料也值得赞赏。

最后一点是,我对“网络代码”这个领域非常新,这样,如果你如此解释,我就知道什么,我就算不了。

最佳回答

You can click on just about anything by generating an actual click event. No href is required and this technique is great for activating modern, javascript-powered controls on "web 2.0" sites.

即使在<代码>.click(>)或j Query s `.click() 不适用t时,该方法仍有效。 (But,在every控制下没有任何方法。)

www.un.org/spanish/ecosoc Plain Javagust (the Works on >, Mack, Greasemonkey,and others):

var clickTarget = document.querySelector ("Any valid CSS selector");
var clickEvent  = document.createEvent ( MouseEvents );
clickEvent.initEvent ( click , true, true);
clickTarget.dispatchEvent (clickEvent);


jQuery version:

var clickTarget = $ ("Any valid jQuery selector");
var clickEvent  = document.createEvent ( MouseEvents );
clickEvent.initEvent ( click , true, true);
clickTarget[0].dispatchEvent (clickEvent);


Note that both of these snippets are for one link/button/etc. at a time.
On AJAX-driven pages, be sure you check that the target node exists first, and wait if necessary.

问题回答

Since you re using JQuery, i assume there is a @require is your script.
// @require http://code.jquery.com/jquery.min.js

Now, why isn t click() working for you?
Do you get any errors in the console?

我尝试了这部法律。

setTimeout(function(){
    alert( about to click/select a radio button )
    $( #radio2 ).prop( checked , true);
    alert( ready to click images with class .imagem ? )
    $( .imagem ).click()
}, 2000)

http://jsfiddle.net/QkCs4/5/“rel=“nofollow” http://jsfiddle.net/QkCs4/5/。

worked fine for me.
see if it works for you.





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签