---
title: "把Tab键全部转换成Enter(回车)键"
author: "foxpro"
date: "2009-07-29T17:00:54Z"
tags: []
slug: "tab-enter"
draft: false
lastmod: "2009-07-29T17:00:54Z"
id: 435652
url: "https://foxpro.iteye.com/blog/435652"
---

var run = function() {
    var all = Ext.query('input'); 
    Ext.each(all, function(o, i, all) { 
                Ext.get(o).addKeyMap({
                    key : 13,
                    fn : function() {
                        try {
                            all.focus()
                        } catch (e) {
                            event.keyCode = 9
                        }
                        if (all
                                && /button|reset|submit/.test(all.type))
                            all.click(); 

                        return true;
                    }
                })
            });
    Ext.getBody().focus(); 

    try {
        var el;
        if (typeof eval(xFocus) == 'object') { 
            el = Ext.getDom(xFocus).tagName == 'input'
                    ? Ext.getDom(xFocus)
                    : Ext.get(xFocus).first('input', true); 
        } else {
            el = all; 
        }
        el.focus();
    } catch (e) {
    }
}
Ext.isReady ? run() : Ext.onReady(run);