• <legend id='aQkiP'><style id='aQkiP'><dir id='aQkiP'><q id='aQkiP'></q></dir></style></legend>

    <tfoot id='aQkiP'></tfoot>
    <i id='aQkiP'><tr id='aQkiP'><dt id='aQkiP'><q id='aQkiP'><span id='aQkiP'><b id='aQkiP'><form id='aQkiP'><ins id='aQkiP'></ins><ul id='aQkiP'></ul><sub id='aQkiP'></sub></form><legend id='aQkiP'></legend><bdo id='aQkiP'><pre id='aQkiP'><center id='aQkiP'></center></pre></bdo></b><th id='aQkiP'></th></span></q></dt></tr></i><div id='aQkiP'><tfoot id='aQkiP'></tfoot><dl id='aQkiP'><fieldset id='aQkiP'></fieldset></dl></div>

      <small id='aQkiP'></small><noframes id='aQkiP'>

          <bdo id='aQkiP'></bdo><ul id='aQkiP'></ul>

        Javascript 可以为我按 Enter 键吗?

        时间:2023-09-07
          <bdo id='82H9l'></bdo><ul id='82H9l'></ul>
            <tbody id='82H9l'></tbody>

        • <tfoot id='82H9l'></tfoot>

          <small id='82H9l'></small><noframes id='82H9l'>

          <i id='82H9l'><tr id='82H9l'><dt id='82H9l'><q id='82H9l'><span id='82H9l'><b id='82H9l'><form id='82H9l'><ins id='82H9l'></ins><ul id='82H9l'></ul><sub id='82H9l'></sub></form><legend id='82H9l'></legend><bdo id='82H9l'><pre id='82H9l'><center id='82H9l'></center></pre></bdo></b><th id='82H9l'></th></span></q></dt></tr></i><div id='82H9l'><tfoot id='82H9l'></tfoot><dl id='82H9l'><fieldset id='82H9l'></fieldset></dl></div>
            1. <legend id='82H9l'><style id='82H9l'><dir id='82H9l'><q id='82H9l'></q></dir></style></legend>

                1. 本文介绍了Javascript 可以为我按 Enter 键吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  有一个网站,我想在我离开时继续点击进入.有没有可能做类似的事情

                  There's a site that I want to continue to hit enter on while I'm away. Is it possible to do something like

                  setInterval(function(){
                      //have javascript press the button with a certain id
                  },100);
                  

                  我想把它放在智能搜索栏中,这样它就可以运行代码了.

                  I was thinking of just putting that in the smart search bar so it would run the code.

                  推荐答案

                  按下回车键会触发一个事件.您必须弄清楚他们正在听哪个事件侦听器.我将在以下示例中使用 keyup:

                  Well pressing enter is triggering an event. You would have to figure out which event listener they are listening to. I'll use keyup in the following example:

                  假设 el 是您想要输入的元素的变量.我不确定你将如何获得该元素,但我相信你知道.

                  Assume el is the variable for the element you want enter to be pressed on. I'm not sure how you going to get that element but I'm sure you know.

                  var evt = new CustomEvent('keyup');
                  evt.which = 13;
                  evt.keyCode = 13;
                  el.dispatchEvent(evt); //This would trigger the event listener.
                  

                  没有办法真正模拟硬件动作.它只是触发事件监听器.

                  There's no way to actually simulate a hardware action. It just triggers the event listener.

                  比如调用el.click()只是调用事件监听的回调,并不是真正的按键.

                  For example calling el.click() is only calling the callback of the event listener, not actually pressing the key.

                  所以你知道当你给一个元素添加一个事件监听器时,第一个参数是 event 对象.

                  So you know how when you add an event listener to an element the first argument is the event object.

                  el.addEventListener('keyup', function(event) {
                     //Do Something
                  });
                  

                  el

                  如果程序员使用:

                  el.onkeyup = function(event) {
                    //do whatever.
                  }
                  

                  这非常简单.

                  只需调用 el.onkeyup(evt);

                  因为 onkeyup 是一个函数.

                  为什么我使用 CustomEvent 而不是 KeyboardEvent 因为 new KeyboardEvent('keyup') 返回的是一个具有 属性的对象keyCode 不使用 Object.definePropertyObject.defineProperties

                  Why did I use CustomEvent instead of KeyboardEvent because new KeyboardEvent('keyup') return's an object with the properties which and keyCode that can't be rewritten without the use of Object.defineProperty or Object.defineProperties

                  这篇关于Javascript 可以为我按 Enter 键吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:数字+空格字符串(信用卡号)的移动友好输入 下一篇:将数组中的字符串值连接到 MongoDB 的单个字段中

                  相关文章

                  最新文章

                2. <legend id='wHtiL'><style id='wHtiL'><dir id='wHtiL'><q id='wHtiL'></q></dir></style></legend>
                    <bdo id='wHtiL'></bdo><ul id='wHtiL'></ul>

                  <small id='wHtiL'></small><noframes id='wHtiL'>

                  <i id='wHtiL'><tr id='wHtiL'><dt id='wHtiL'><q id='wHtiL'><span id='wHtiL'><b id='wHtiL'><form id='wHtiL'><ins id='wHtiL'></ins><ul id='wHtiL'></ul><sub id='wHtiL'></sub></form><legend id='wHtiL'></legend><bdo id='wHtiL'><pre id='wHtiL'><center id='wHtiL'></center></pre></bdo></b><th id='wHtiL'></th></span></q></dt></tr></i><div id='wHtiL'><tfoot id='wHtiL'></tfoot><dl id='wHtiL'><fieldset id='wHtiL'></fieldset></dl></div>

                    <tfoot id='wHtiL'></tfoot>