e.keyCode does not work

后端 未结 6 564
天命终不由人
天命终不由人 2021-01-23 08:56

I would like to ask you about something that does not work for me ? If you could help me please.

Html:



        
6条回答
  •  借酒劲吻你
    2021-01-23 09:22

    With minimum modifications ,

    
    
    function doSomething(e){
    var comment = $(".blabla").val();
    var id = this.id;
    alert(e.keyCode) // Now it should work
    }
    

    The first parameter in the doSomething function will be the event object. The this variable will return a reference to the input element.

    If you modify your posted js and provide a name to the function as I have done without making changes to the function parameters, you will find that id will contain the event object.

提交回复
热议问题