当前位置: 代码迷 >> Web前端 >> jquery 兼容 ie跟firefox上的 change enter to tab
  详细解决方案

jquery 兼容 ie跟firefox上的 change enter to tab

热度:857   发布时间:2012-07-31 12:33:47.0
jquery 兼容 ie和firefox上的 change enter to tab
$(document).keydown(function(event){
if(event.which==13){
if($.browser.msie) {//IE
                  window.event.keyCode=9;
                }else//其它只测了fireforx
                {
                    var $target = $(event.target);
                     var textboxes = $("input,select");
                     var currentBoxNumber = textboxes.index($target);
                   
                    if (textboxes[currentBoxNumber + 1] != null) {
                            var nextBox = textboxes[currentBoxNumber + 1]
                            nextBox.focus();
                            nextBox.select();

                    }else{
                        var nextBox = textboxes[0]
                            nextBox.focus();
                            nextBox.select();
                    }
                        
                    event.preventDefault();
                    return false;
                }    
      }
//说明,对于firefox的做得不完善,希望今后有人看到了提示一下或者发现更好的更新一下
  相关解决方案