Easyui下的点击回车键跳转到下个控件

2023-02-21,,

在Easyui框架下,JavaScript 中的 onKeyDown事件居然失效了。所以使用了另外的函数去实现点击回车键跳转到下个控件

 /**
* 点击回车键跳转到下个控件;
* @param oldId 被点击的textbox
* @param newId 下个要选中的控件ID
*/
function keydownText(oldId,newId){
var col=document.getElementById(oldId);
if(col.className=='easyui-combobox'){
$('#'+oldId).combobox({
inputEvents: $.extend({}, $.fn.combobox.defaults.inputEvents, {
keydown: function (e) {
if (e.keyCode == 13) {
$('#'+oldId).combobox('hidePanel');
$('#'+newId).textbox('textbox').focus();
}
else if (e.keyCode == 40) {
$('#'+oldId).combobox('showPanel');
}
}
})
});
}
else if(col.className=='easyui-numberbox'){
$('#'+oldId).numberbox({
inputEvents: $.extend({}, $.fn.numberbox.defaults.inputEvents, {
keydown: function (e) {
if (e.keyCode == 13) {
$('#'+newId).textbox('textbox').focus();
}
}
})
});
}
else {//if(col.className=='easyui-textbox')
$('#'+oldId).textbox({
inputEvents: $.extend({}, $.fn.textbox.defaults.inputEvents, {
keydown: function (e) {
if (e.keyCode == 13) {
$('#'+newId).textbox('textbox').focus();
}
}
})
});
}
}

keydownText函数

2.前台页面

 <tr>
<td class="pe-label">学历:</td>
<td class="pe-content">
<input id="baseinfo_base19" name="baseinfo_base19" class="easyui-combobox">
</td>
<td class="pe-label">目前职业:</td>
<td class="pe-content">
<input id="baseinfo_base20" name="baseinfo_base20" class="easyui-combobox">
</td>
<td class="pe-label">工作单位:</td>
<td class="pe-content">
<input id="baseinfo_base21" name="baseinfo_base21" class="easyui-textbox">
</td>
</tr>

html代码

3.在JS页面中的引用

 $(function(){
keydownText('baseinfo_base19','baseinfo_base20');
keydownText('baseinfo_base20','baseinfo_base21');
});

实现功能

不过这个函数在对combox的回车键跳转时,存在一点问题,有待解决中。

Easyui下的点击回车键跳转到下个控件的相关教程结束。

《Easyui下的点击回车键跳转到下个控件.doc》

下载本文的Word格式文档,以方便收藏与打印。