jQuery keyup function doesnt work?

后端 未结 4 1005
陌清茗
陌清茗 2021-01-12 13:51

My HTML file:



  
  

        
4条回答
  •  清酒与你
    2021-01-12 14:26

    Apart from a typo around your missing }, when your script.js file runs (in the 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

            
        
    
    

    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');
    });
    

提交回复
热议问题