思路:
1、使用document.addEventListener("keydown",btChange,false);添加 一个键盘事件(该事件必须有一输入控件得到焦点才能触发,这个必须好好控制)
2、使用actionsheet.down('.button'),获取第一个button
3、获取后为一个button对象,使用nextSibling()、previousSibling()方法获取当前按钮对象的上一级或下一级组件(该方法能得到同一树层级中的对象)
3、使用removeCls("x-button-normal")跟addCls("x-button-action")变化按钮,实现按钮选中状态或为选中状态的视觉变化,里面的样式可自己设定
4、另外要获取第一个按钮一级最后一个按钮,以实现菜单的循环
以下为代码,可写与actionsheet的show()事件中,实现监听android手机键盘
var bt_check var bt_first var bt_last bt_check = comp.down('.button') bt_first = comp.down('.button') bt_last = comp.down('.button').nextSibling().nextSibling().nextSibling().nextSibling() bt_check.removeCls("x-button-normal"); bt_check.addCls("x-button-action"); document.addEventListener("keydown",btChange,false); function btChange(){ var e = window.event.keyCode; if(e == 56 || e == 54){ var bt_check_next = bt_check.nextSibling() //返回该组件之后的组件(处于同一树层级中) if(bt_check_next){ bt_check.removeCls("x-button-action"); bt_check.addCls("x-button-normal"); bt_check_next.removeCls("x-button-normal"); bt_check_next.addCls("x-button-action"); bt_check = bt_check_next } else{ bt_check.removeCls("x-button-action"); bt_check.addCls("x-button-normal"); bt_check = bt_first; bt_check.removeCls("x-button-normal"); bt_check.addCls("x-button-action"); } } else if(e == 50 || e == 52){ var bt_check_previous = bt_check.previousSibling() //返回该组件之前的组件(处于同一树层级中) if(bt_check_previous){ bt_check.removeCls("x-button-action"); bt_check.addCls("x-button-normal"); bt_check_previous.removeCls("x-button-normal"); bt_check_previous.addCls("x-button-action"); bt_check = bt_check_previous } else{ bt_check.removeCls("x-button-action"); bt_check.addCls("x-button-normal"); bt_check = bt_last; bt_check.removeCls("x-button-normal"); bt_check.addCls("x-button-action"); } } else if(e == 13 || e == 53){ bt_check.callHandler() //触发按钮的handler事件 } }