读书人

用Enter顶替Tab

发布时间: 2012-11-03 10:57:43 作者: rapoo

用Enter代替Tab
转自:http://hi.baidu.com/_ollie/blog/item/9722df133d3d26d8f7039e95.html

ExtJs中Enter代替Tab javascript
2009/03/28 15:59
近来客户有提出需求,就是尽量减少表单输入时的鼠标动作。
那么就涉及到像CS中的Enter键跳转下一有效位的问题。 从网上有收到很多关于JS的相关解决方案。 但是其下的处理方式就能达到我的需求。 很好的,也可以作为其他JS相关功能的参考

var run = function() {    var all = Ext.query('input[type!=hidden]'); // 查找所有非藏元素    Ext.each(all, function(o, i, all) { // 遍添加enter的                Ext.get(o).addKeyMap({                    key : 13,                    fn : function() {                        try {                            all[i + 1].focus()                        } catch (e) {                            event.keyCode = 9                        }                        if (all[i + 1]                                && /button|reset|submit/.test(all[i + 1].type))                            all[i + 1].click(); // 如果click事件                        return true;                    }                })            });    Ext.getBody().focus(); // 使面取焦,否下面定默焦的功能不    try {        var el;        if (typeof eval(xFocus) == 'object') { // 如果入的是id或dom            el = Ext.getDom(xFocus).tagName == 'input'                    ? Ext.getDom(xFocus)                    : Ext.get(xFocus).first('input', true); // 找到input框        } else {            el = all[xFocus || 0]; // 通索引找        }        el.focus();    } catch (e) {    }}Ext.isReady ? run() : Ext.onReady(run); // 面加完成後添加表航

读书人网 >其他相关

热点推荐