选项卡按钮在表单文本字段中不起作用
我有一个表单,其中使用 4 个文本字段。
文本字段1 文本字段2 文本字段3 textfield4
我正在调用 textfield2 和 textfield3 上“onpress”事件的函数,以仅检查整数值。该函数如下所示。
function checkIntnumber(obj,event){
var unicode=event.charCode? event.charCode : event.keyCode
if((unicode==37 || unicode==39 || unicode==35 || unicode==36 || unicode==46)
&& event.which==0) {//if the key isn't the (BackSpace/Left Arrow/Right
Arrow/Delete/Home/End) key (which we should allow)
return true;
} else if(unicode!=8) {
if (unicode>=48 && unicode<=57) { //if a number
return true; //enable key press
} else {
return false; //disable key press
}
}
}
现在,我使用 Tab 键从 textfield1 移动到 textfield2,这工作正常,但 Tab 键无法从 textfield2 移动到 textfield3 或 textfield3 移动到 textfield4。此问题仅发生在 Mozilla Firefox 中。请帮我。 谢谢
编辑:答案下评论中的代码 -
<input type="text" name="from" id="from" style="width:50px;"
onkeypress="hideRateDiv();return checkIntnumber(this,event)"/>
- <input type="text" name="to" id="to" style="width:50px;"
onkeypress="hideRateDiv();return checkIntnumber(this,event)" tabindex="2"/>
i have a form in which i am using 4 textfields.
textfield1
textfield2
textfield3
textfield4
i am calling a function on "onpress" event on textfield2 and textfield3 for checking only integer values. the function is given below.
function checkIntnumber(obj,event){
var unicode=event.charCode? event.charCode : event.keyCode
if((unicode==37 || unicode==39 || unicode==35 || unicode==36 || unicode==46)
&& event.which==0) {//if the key isn't the (BackSpace/Left Arrow/Right
Arrow/Delete/Home/End) key (which we should allow)
return true;
} else if(unicode!=8) {
if (unicode>=48 && unicode<=57) { //if a number
return true; //enable key press
} else {
return false; //disable key press
}
}
}
now then i move from textfield1 to textfield2 using tab key this is working fine but tab key is not working to move from textfield2 to textfield3 or textfield3 to textfield4. this problem is occuring in mozilla firefox only. please help me.
thanks
EDIT: code from the comment under the answer -
<input type="text" name="from" id="from" style="width:50px;"
onkeypress="hideRateDiv();return checkIntnumber(this,event)"/>
- <input type="text" name="to" id="to" style="width:50px;"
onkeypress="hideRateDiv();return checkIntnumber(this,event)" tabindex="2"/>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您只需测试与 Tab 键 (
9
) 对应的代码并返回 true。编辑:抱歉,刚刚看到克里斯蒂安的评论并更仔细地阅读了问题。可能存在 tabindex 问题,但如果这四个字段在源 HTML 中紧邻定义,则不应存在 tabindex 问题。但考虑到您发布的代码似乎不允许使用 Tab 键,我不明白 Tab 键在您的字段 1 和 2 之间如何工作 - 它不应该在它们中的任何一个之间工作。
您能否发布这些字段的 HTML 并显示您如何分配按键事件?
You just need to test for the code that corresponds to the tab key (
9
) and return true.EDIT: Sorry, just saw Christian's comment and read the question a bit more carefully. There could be a tabindex issue, but there shouldn't be if the four fields are defined right after each other in your source HTML. But given that the code you posted doesn't seem to allow the tab key I don't understand how tabbing would work between your field 1 and 2 - it shouldn't work between any of them.
Can you please post the HTML for those fields and show how you assign the keypress event?
if((unicode==37 || unicode==39 || unicode==35 || unicode==36 || unicode==46 || unicode==9) && event.which== 0)
像这样更改 if 条件,选项卡的键码也如此(即 9)if((unicode==37 || unicode==39 || unicode==35 || unicode==36 || unicode==46 || unicode==9) && event.which==0)
Change the if condition like this, keycode for tab also (that is 9)