Detect enter in input elements of a certain class

前端 未结 3 968
陌清茗
陌清茗 2021-02-19 19:57

I need to detect when someone hits \"enter\" in text inputs with a specific class.

My jQuery is as follows:

$(\'input.large\').keypress(function (e) {
           


        
3条回答
  •  盖世英雄少女心
    2021-02-19 20:18

    check this one: http://jsfiddle.net/EJyyr/

    used this html:

     Personal Name 
      
    
     Email
      
    

    and this is the jQuery which logs the input text id

    $('.large').keypress(function (e) {
       if(e.which ==13)
        console.log($(this).attr('id'));
    });
    

提交回复
热议问题