preventDefault in Safari

后端 未结 3 879
轮回少年
轮回少年 2021-01-25 16:53

I have a textbox which has the code;


Now there is no e

相关标签:
3条回答
  • 2021-01-25 16:56

    in jQuery

    //Press Enter in INPUT moves cursor to next INPUT
    $('#form').find(':input').keypress(function(e){
        if ( e.which == 13 )
        {
            $(this).next().focus();  //Use whatever selector necessary to focus the 'next' input
        }
    });
    

    JAVASCRIPT

    <script language="JavaScript">
    function disableEnterKey(e)
    {
         var key;
         if(window.event)
              key = window.event.keyCode;     //IE
         else
              key = e.which;     //firefox
         if(key == 13)
              return false;
         else
              return true;
    }
    </script>
    

    and write

    <input type=”text” name=”mytext” onKeyPress=”return disableEnterKey(event)”>
    
    0 讨论(0)
  • 2021-01-25 17:03

    use event.preventDefault() or return False should do the trick for you.

    0 讨论(0)
  • 2021-01-25 17:15

    Just to be sure, terminate your callback function with a return false. That should do the trick.

     function(e) {
         e.preventDefault();
         // some awesome code
         return false;
     }
    

    Oh, and another thing: in the future, to avoid such random behavior.. respect the standards, use a form :)

    0 讨论(0)
提交回复
热议问题