当我按下 Enter 键时,按键事件不会被触发
我已将按键事件附加到我的文本框。当用户按下其他键时,我正在做一些处理工作,但是当用户按下 Enter 键时,我正在将文本框中的值提交到某个服务器。我能够完成所有处理,一切都很好,但是当我按 Enter 键时,事件不会被触发。所以,我无法将我的值提交到服务器。
这是我的代码:
$("#txt" + filterID).keypress(txtInput_keypress);
function txtInput_keypress(e) {
var code = (e.keyCode ? e.keyCode : e.which);
var strValue = $(this).val()+ String.fromCharCode(e.which);
var bool = $.trim(strValue).match(reg);
if (code == 13) {
//textbox value submission code
}
else if (parseFloat($.trim(strValue)) > max) {
e.preventDefault();
}
else if (bool) {
return true;
}
else {
e.preventDefault();
}
}
我的代码有什么问题吗?请有人帮我解决这个问题。
I have attached a keypress event to my textbox. when the user presses other keys i am doing some processing work, but when the user presses the Enter key i am submitting the value in the textbox to some server. I am able to do all processing and every thing is fine, but when i press enter key the event is not getting fired. so, i ma unable to submit my value to the server.
Here is my code:
$("#txt" + filterID).keypress(txtInput_keypress);
function txtInput_keypress(e) {
var code = (e.keyCode ? e.keyCode : e.which);
var strValue = $(this).val()+ String.fromCharCode(e.which);
var bool = $.trim(strValue).match(reg);
if (code == 13) {
//textbox value submission code
}
else if (parseFloat($.trim(strValue)) > max) {
e.preventDefault();
}
else if (bool) {
return true;
}
else {
e.preventDefault();
}
}
whats wrong with my code? Please somebody help me to fix this issue.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)