开发者

Execute function when enter is pressed if textbox has focus

Is it possible to execute a funct开发者_运维问答ion by pressing the enter key on the keyboard only if a certain textbox has focus. i.e. if any other textbox has focus or no textbox has focus, the enter key should do nothing.


$('#myTextbox').bind('keyup', function(e) {

    if ( e.keyCode === 13 ) { // 13 is enter key

        // Execute code here.

    }

});


$(function(){
     $("#textarea").keyup(function(e){
          if (e.keyCode === 13) {
               //do stuff
          }
     });

});


Enter any thing in Text box then press Enter to execute

 <form onSubmit='alerttest(this); return false'>        
     <input type="text">         
 </form>


 <script language="javascript">
   function alerttest()
    {
        alert("Executing jolly.exe !!!!");
        // function edited by Inderpreet singh
    }
</script>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜