使用“Enter”搜索功能关键是日文 [英] Search function with "Enter" key in Japanese

查看:111
本文介绍了使用“Enter”搜索功能关键是日文的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我面对日本人的问题。我有一个允许用户搜索数据的表单。当用户输入字符串进行搜索并按下Enter键时,将执行搜索功能。我的代码是:

  $('#formSearch input')。keyup(function(event){
var key = event.charCode || event.keyCode || 0;
if(key == 13){
$(#formSearch)。submit();
}
});

但是当用户在平假名模式下输入日语时,编辑器会显示预测单词。他们按下Enter并执行搜索功能。它不正确。任何人都可以告诉我如何解决这个问题。非常感谢您

解决方案

这是因为您正在监听输入按键(键入)。
您可能知道,在平假名模式下输入日语时,键入时会出现可能的汉字字符列表。 Enter 是用于确认汉字选择的键之一,因此大多数日本用户在搜索某些内容时最终会按 Enter 两次。您的脚本会在第一次按下时执行,因此第二次提交按钮将被忽略。



更好的选择是监听 submit 事件而不是 keyup 事件。在jQuery中,您可以使用 .submit() 方法是这样的:

  $(#formSearch)。submit(function(){
// Code在这里执行
});

然而,在您的情况中,您似乎没有任何进一步的脚本来执行,所以也许你根本不需要JavaScript。试用没有JavaScript的表单—如果您不能使用 Enter (英文或日文)提交,那么您的HTML可能存在问题,请使用表单的代码更新您的问题。

I am facing a problem with Japanese. I have a form that allows users can search the data. When users input the string to search and press "Enter" key, the search function will execute. My code is:

$('#formSearch input').keyup(function(event){
    var key = event.charCode||event.keyCode||0;
    if(key == 13){
         $("#formSearch").submit();
    }
});

But when users input Japanese in Hiragana mode, the editor show the predict words. They press "Enter" and the search function is execute. It does not correct. Anyone can tell me how to fix this problem.Thank you so much

解决方案

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.

A better alternative is to listen for a submit event instead of a keyup event. In jQuery you can use the .submit() method like this:

$("#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.

这篇关于使用“Enter”搜索功能关键是日文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆