我在日语方面遇到了问题。我有一个允许用户搜索数据的表单。当用户输入要搜索的字符串并按“Enter”键时,搜索功能就会执行。我的代码是:
$('#formSearch input').keyup(function(event){
var key = event.charCode||event.keyCode||0;
if(key == 13){
$("#formSearch").submit();
}
});
但是当用户以平假名模式输入日语时,编辑器会显示预测单词。他们按下“Enter”键,搜索功能就会被执行。它不正确。任何人都可以告诉我如何解决这个问题。非常感谢
This is because you're listening for an Enter key press (keyup).
As you probably know, when typing Japanese in Hiragana mode, a list of possible kanji characters appears as you type. Enter is one of the keys used to confirm the kanji selection so most Japanese users will end up pressing Enter twice when they search for something. Your script executes on the first press so the second "submit" press is ignored.
更好的选择是聆听submit
事件而不是keyup
事件。在 jQuery 中你可以使用.submit() http://api.jquery.com/submit/
像这样的方法:
$("#formSearch").submit(function() {
// Code to execute here
});
In your case, however, you don't seem to have any further script to execute, so maybe you don't need JavaScript at all. Try the form without JavaScript — if you can't submit it with Enter (in English or Japanese) there's probably a problem with your HTML so please update your question with your form's code.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)