Replace keyCode in IE 11

后端 未结 4 928
执笔经年
执笔经年 2021-01-18 20:37

We use this code for simulating Tab key with Enter key:

function EnterTab() {
    if (event.keyCode == 13) event.keyCode = 9;
    retur         


        
4条回答
  •  不思量自难忘°
    2021-01-18 20:59

    This worked in IE9 but no longer works in IE11.So you have to find a solution that stimulates the result you want.For example, if you want to allow users to press 'Enter' to go to the next data entry field (like tab does), try something like this.

    var i = 0;
    var els = myform.getElementsByTagName('input').length
    document.onkeydown = function(e) {
      e = e || window.event;
      if (e.keyCode == 13) {
        i++;
        i > els - 1 ? i = 0 : i = i;
        document.myform[i].focus();
    
      }
    };
    Press 'enter' inside text to act like tab button
    

    jQuery Example:

    $('.info').bind('keypress', function(event) {
      if (event.which === 13) {
        var nextItem = $(this).next('.info');
    
        if (nextItem.size() === 0) {
          nextItem = $('.info').eq(0);
        }
        nextItem.focus();
      }
    });
    
    
    
    

提交回复
热议问题