【问题标题】:Onkeyup is not working [closed]Onkeyup 不工作[关闭]
【发布时间】:2016-12-24 05:17:16
【问题描述】:

虽然我可以在 chrome 控制台中看到“onkeyup”事件,但无论出于何种原因,该事件都没有触发。

var el = document.getElementById("userInput");
el.addEventListener("onkeyup", function() {
    alert('yahoooo0');
});
<input type="text" id="userInput" name="food"/>
    
    

【问题讨论】:

    标签: javascript onkeyup


    【解决方案1】:

    将您的 event listeneronkeyup 更新为 keyup

    var el = document.getElementById("userInput");
    el.addEventListener("keyup", function() {
        alert('yahoooo0');
    });
    <input type="text" id="userInput" name="food"/>
        

    【讨论】:

      【解决方案2】:

      试试这个:

      $("#userInput").keyup(function() {
         alert('yahoooo0');
      });
      

      test on fiddle

      【讨论】:

      • 该问题未标记Jquery
      【解决方案3】:

      您可以将 eventlistener 名称从 onkeyup 更改为 keyup 或者您可以使用以下简单的 eventlistenter 附加方法

      <input type="text" id="userInput" name="food" onkeyup="doSomething()"/>
      

      【讨论】:

        【解决方案4】:
        el.addEventListener("keyup", function() {
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2018-12-20
          • 2013-02-04
          • 2014-05-04
          • 2016-04-26
          • 2012-10-08
          • 2012-01-12
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多