JS插件点击网页上的按钮

qq_25604135 2017-07-16 11:10:40
2个网页上的按键

<a class="treasureMapPopup-action-button highlight" href="#" onclick="app.views.TreasureMapView.map.toggleTabState('upgradeMap'); return false;">UPGRADE</a>

<a href="#" class="treasureMapPopup-action-button highlight" onclick="app.views.TreasureMapView.map.discard(this); return false;">Leave</a>

我想点击下面这个LAEVE的按键

var poster=document.getElementsByClassName(' ')

;poster[poster.length-1].onclick();

中间(' ') 要填写什么呢 我填写了treasureMapPopup-action-button highlight 效果就是等于按了上面第一行的
...全文
321 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
qq_25604135 2017-07-19
  • 打赏
  • 举报
回复
引用 3 楼 showbo 的回复:
[quote=引用 2 楼 qq_25604135 的回复:] [quote=引用 1 楼 net_lover 的回复:] 你两个链接的class完全相同了,你需要加一个不同的才能知道是哪个,如 <a href="#" class="treasureMapPopup-action-button highlight J_Leave" onclick="app.views.TreasureMapView.map.discard(this); return false;">Leave</a> document.getElementsByClassName('J_Leave')
可是网页上就是这样的 我该怎么办[/quote] 你代码不是写好了??填写a中任意一个样式就行了 var poster=document.getElementsByClassName('treasureMapPopup-action-button') poster[poster.length-1].onclick(); 不过你得确认只存在着2个按钮,如果有多个你得确认离开dom对象的下标位置,或者遍历poster找到内容为Leave的按钮 var poster=document.getElementsByClassName('treasureMapPopup-action-button') for(var i=0;i<poster.length;i++)if(poster[i].innerHTML=='Leave'){poster[i].onclick();break;}[/quote]
引用 3 楼 showbo 的回复:
[quote=引用 2 楼 qq_25604135 的回复:] [quote=引用 1 楼 net_lover 的回复:] 你两个链接的class完全相同了,你需要加一个不同的才能知道是哪个,如 <a href="#" class="treasureMapPopup-action-button highlight J_Leave" onclick="app.views.TreasureMapView.map.discard(this); return false;">Leave</a> document.getElementsByClassName('J_Leave')
可是网页上就是这样的 我该怎么办[/quote] 你代码不是写好了??填写a中任意一个样式就行了 var poster=document.getElementsByClassName('treasureMapPopup-action-button') poster[poster.length-1].onclick(); 不过你得确认只存在着2个按钮,如果有多个你得确认离开dom对象的下标位置,或者遍历poster找到内容为Leave的按钮 var poster=document.getElementsByClassName('treasureMapPopup-action-button') for(var i=0;i<poster.length;i++)if(poster[i].innerHTML=='Leave'){poster[i].onclick();break;}[/quote] F12 我调试可以 但是放进JS插件里不行 应该怎么写啊
VIctor_Ye 2017-07-18
  • 打赏
  • 举报
回复
这里的问题主要是你这两个链接的类是同一个名字,把两一个class的名字改成不同的就好了,或者设个id,document.getElementById("")
  • 打赏
  • 举报
回复
引用 2 楼 qq_25604135 的回复:
[quote=引用 1 楼 net_lover 的回复:] 你两个链接的class完全相同了,你需要加一个不同的才能知道是哪个,如 <a href="#" class="treasureMapPopup-action-button highlight J_Leave" onclick="app.views.TreasureMapView.map.discard(this); return false;">Leave</a> document.getElementsByClassName('J_Leave')
可是网页上就是这样的 我该怎么办[/quote] 你代码不是写好了??填写a中任意一个样式就行了 var poster=document.getElementsByClassName('treasureMapPopup-action-button') poster[poster.length-1].onclick(); 不过你得确认只存在着2个按钮,如果有多个你得确认离开dom对象的下标位置,或者遍历poster找到内容为Leave的按钮 var poster=document.getElementsByClassName('treasureMapPopup-action-button') for(var i=0;i<poster.length;i++)if(poster[i].innerHTML=='Leave'){poster[i].onclick();break;}
qq_25604135 2017-07-16
  • 打赏
  • 举报
回复
引用 1 楼 net_lover 的回复:
你两个链接的class完全相同了,你需要加一个不同的才能知道是哪个,如 <a href="#" class="treasureMapPopup-action-button highlight J_Leave" onclick="app.views.TreasureMapView.map.discard(this); return false;">Leave</a> document.getElementsByClassName('J_Leave')
可是网页上就是这样的 我该怎么办
孟子E章 2017-07-16
  • 打赏
  • 举报
回复
你两个链接的class完全相同了,你需要加一个不同的才能知道是哪个,如 <a href="#" class="treasureMapPopup-action-button highlight J_Leave" onclick="app.views.TreasureMapView.map.discard(this); return false;">Leave</a> document.getElementsByClassName('J_Leave')

87,994

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧