带类型或值标签的自动点击
亲爱的朋友,我有一个网站,我希望为其创建用于自动单击的javascript小书签,但是该网站未使用ID标签.这是网站的代码:-
Dear friends i have site for which i would like to create javascript bookmarklet for autoclick, but the site does not use ID tag. here is the code of site :-
<input type="submit" name="Submit" value="Find Product"
onclick="return incrementClicksTest('2','true')" class="buttonSubmit">
我使用了此JavaScript小书签
I used this JavaScript bookmarklet
javascript:document.getElementById('any_id_here').click()
可以很好地使用id,我该如何使用名称,值和类型标记制作小书签
workes fine for id, how do i go about making bookmarklet using name,value and type tag
谢谢跳舞!
使用以下内容:
document.getElementsByTagName("input")[0].click();
示例代码: http://jsfiddle.net/dcRsc/
现在,如果您的按钮是页面中的第一个输入,那将起作用.
Now, that will work if your button is the first input in your page.
如果页面中包含许多元素,请使用此选项:
Use this if you have numerous elements in your page:
var elems =document.getElementsByTagName("input");
for(var i=0;i<elems.length;i++)
{
if(elems[i].type=="submit" && elems[i].name =="Submit")
{
elems[i].click();
break;
}
}
示例代码: http://jsfiddle.net/dcRsc/1/
这将触发带有提交名称的提交按钮的click
事件.
That will trigger the click
event of your submit button, with Submit name.
此外(由于您的按钮已经具有css类),您可以使用getElementsByClassName()
方法:
Furthermore (and since your button already has a css class) you could use the getElementsByClassName()
method:
var elems =document.getElementsByClassName("buttonSubmit");
for(var i=0;i<elems.length;i++)
{
if(elems[i].name =="Submit")
{
elems[i].click();
break;
}
}
示例代码: http://jsfiddle.net/dcRsc/2/
这将获得应用buttonSubmit
类的所有元素.
That will get all elements with the buttonSubmit
class applied.
或
document.getElementsByClassName("buttonSubmit")[0].click();
如果您的按钮是页面上唯一带有该类的元素,则完全避免for
循环.
If your button is the only element in the page with that class on it, hence avoiding the for
loop altogether.