简体   繁体   中英

creating a custom keyboard shortcut using javascript

I work in a tour company where we make bookings and the system they are using requires lots of typing and clicking. To make my work easier I have installed a Google Chrome Extension where you can run a javascript code via keyboard shortcut. I was able to make it work on most of the buttons by using getElementsByClassName and getElementById but there is this certain button where I can't make it work.

the button code is

A href class="button" name="cmdJn" onclick="fnOptionsClear(); return false;

What should be the code? In other buttons I use document.getElementsByClass('bob')[0].click() and it works

I'm just new to javascript. thanks

Is your issue that the element doesn't have an id or unique class on it? If so you can do something like document.querySelector('[name="cmdJn"]') .

document.querySelector allows you to use css selectors to find elements. You can find out more about css selectors here

When you are using the document.getElementsByClass('bob') code you are attempting to select something that has the class of "bob". Your element has the class of button. Change the class element into bob, or run the code document.getElementsByClass('button')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM