jQuery keyup function doesnt work?

会有一股神秘感。 提交于 2019-12-01 04:10:55

Apart from a typo around your missing }, when your script.js file runs (in the <head> section), the rest of your document does not exist. The easiest way to work around this is to wrap your script in a document ready handler, eg

jQuery(function($) {
    $('#workerID').on('keyup', function() {
        alert('key up');
    });
});

Alternatively, you could move your script to the bottom of the document, eg

        <script src="js/scripts.js"></script>
    </body>
</html>

or use event delegation which allows you to bind events to a parent element (or the document), eg

$(document).on('keyup', '#workerID', function() {
    alert('key up');
});

You're missing the curly bracket to close the function:

$('#workerID').keyup(function() {
    alert('key up');
});

Errors like these are usually seen in the browser's JavaScript console.

Rituraj ratan

in HTML

inser id, name,vale in " "

<div class="loginForm">
  <p>Worker-ID:<input type="text" id="workerID" name="workerID" /></p>
  <p>Password:<input type="password"  id="workerPassword" name="workerPassword" /></p>
  <input type="submit" id="submitLogin" name="submitLogin" value="Log in"/>
</div>

in js

$('#workerID').keyup(function() {
       alert('key up');} // here you forget "}"
      );

demo

Syntax is wrong see here

$( document ).ready(function() {
   $( "#workerID" ).keyup(function() {
    .....................
   });
});

change ); to });

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!