Javascript 书签,用于单击按唯一名称找到的按钮
我需要一个可以单击按钮的 JavaScript 书签。问题是,页面上有 100 多个按钮,它们的值都相同。这个名字很独特,但很长。
该元素的全名类似于:
actions[http://apps.facebook.com/frontierville/giftaccept.php?next=giftaccept.php&senderId=1%3A1325206719&gh=3a8bfdace76051752a9127d1f9b43872&gift=nails&timestamp=1285598414&ref=tab&key=29b15e06ed9d7c00a8870c955ab938cf%24%24cfH1PUUZ%217bZYhg8M-o-XQc%218HHRMcvvyhuf4d%21.64qEvlQe&src=request&aff=gift&crt=nails&signature=6dd3fa03fe88f98b6dcab4faf4c7da94]
每个按钮的值都是 Accept 和 Play。
所以。有没有办法让它点击名称中带有特定 URL 的按钮?
以下是其中一个按钮的信息来源(从 chrome 的检查元素功能中获取):
<input value="Accept and Play" type="submit" name="actions[http://apps.facebook.com/onthefarm/giftaccept.php?senderId=1259413693&gift=mysterygift&timestamp=1285599906&ref=gift_accept_tab&key=78fcc7de3b36b8f9564262fab506893f%24%24ceK5RVRY61bZYhg8M-o-XQcyL%2CzHccEwEeuj4e-%21-dh0AD0A2AgyScd&signature=32db959ce43f8330cf8fd992fbd53a51&srcapp=FarmVille]">
I need a javascript bookmarklet which can click on a button. The thing is, there are 100+ buttons on the page all with the same value. The name is unique but quite long.
The full name of the element is something like :
actions[http://apps.facebook.com/frontierville/giftaccept.php?next=giftaccept.php&senderId=1%3A1325206719&gh=3a8bfdace76051752a9127d1f9b43872&gift=nails×tamp=1285598414&ref=tab&key=29b15e06ed9d7c00a8870c955ab938cf%24%24cfH1PUUZ%217bZYhg8M-o-XQc%218HHRMcvvyhuf4d%21.64qEvlQe&src=request&aff=gift&crt=nails&signature=6dd3fa03fe88f98b6dcab4faf4c7da94]
The value of every button is Accept and Play.
So. Is there a way to have it click on the button with a specific URL in the name?
Here is the source of the info for one of the buttons (got this from chrome's inspect element feature):
<input value="Accept and Play" type="submit" name="actions[http://apps.facebook.com/onthefarm/giftaccept.php?senderId=1259413693&gift=mysterygift×tamp=1285599906&ref=gift_accept_tab&key=78fcc7de3b36b8f9564262fab506893f%24%24ceK5RVRY61bZYhg8M-o-XQcyL%2CzHccEwEeuj4e-%21-dh0AD0A2AgyScd&signature=32db959ce43f8330cf8fd992fbd53a51&srcapp=FarmVille]">
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这应该可以做到...
它基于
getElementsByName
,这里已经全部写出来了...This should do it...
It's based on
getElementsByName
, here it is all spelled out...这是您可能想要执行的操作的粗略示例。
如果 url 每次都会更改,您可以找到某种方法来填充 url 变量,并使用它来生成元素名称。此示例假设该元素是页面上唯一具有该确切
name
属性的元素。这个示例非常严格,如果您需要与之交互,可能无法用作您的小书签。其他元素是什么样子的?寻找指向giftaccept url 或类似内容的元素会更好吗?在这种情况下,脚本会有更大的灵活性。
Here's a rough example of what you might want to do.
if the url is going to change every time, you can find someway to fill the
url
variable, and use that to generate the element name. This example assumes that element is the only one on the page with that exactname
attribute.This example is pretty rigid and may not work as your bookmarklet if you need to interact with it. What do the other elements look like? Would it be better to look for an element pointing to the
giftaccept
url or something like that? The script would have a lot more flexibility in a situation like that.为了方便和兼容性,使用 JQuery 选择器:
For convenience and compatibility use JQuery selectors: