JavaScript从Chrome控制台按名称单击按钮 [英] JavaScript click a button by name from chrome console

查看:252
本文介绍了JavaScript从Chrome控制台按名称单击按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用chrome控制台以编程方式点击网页中的按钮。

I'm trying to click programmatically a button from a web page using chrome console.

(更新)按钮的代码如下所示:

(UPDATED)The code of the button looks like this :

<FORM METHOD=GET ACTION="/xxx/yyy/kkk.jsp" >
    <INPUT type="hidden" name="page" value="721">
    <INPUT type="hidden" name="reqType" value="ReprintO">
    <INPUT type="hidden" name="title" value="Reprint Label">
    <INPUT type="hidden" name="system" value="reprint">
    <td align=right width=25%><input type=submit value='>' name=BTN_CHOICE5/>
    <td>&nbsp;&nbsp;Reprint Label
</form>

页面上还有几个按钮 value ='> ;',所以我想我需要用名字点击它。我尝试了
document.querySelector('input [name =BTN_CHOICE4]')。click(); 并且它不起作用。如何使用JS单击此按钮?

There are a couple more buttons on the page that have value= '>', so I guess I need to click it using name. I tried document.querySelector('input[name="BTN_CHOICE4"]').click(); and it didn't work. How do I click this button using JS?

推荐答案

如果您有ID属性,可以使用

If you have ID attribute you can use

$('#btnId').click();

或者如果你想通过名字去,你可以使用

Or If you want to go by name, you can use

$('[name="someName"]').click();

但如果您使用Id而不是名称,就好像多个控件具有相同的名称属性一样好和值,然后将调用所有这些控件click事件。

But it would be good if you use by Id not by name as if multiple controls have same name attribute and value, then all those controls click event will be invoked.

这篇关于JavaScript从Chrome控制台按名称单击按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆