欢迎您来到,李雷博客 | PHP博客        登录  |  注册

通过JQ判断input当前输入法是中文还是英文模式

更新:2022-12-10 22:06:21
人气:744
来源:本站原创
A+

项目中要实现扫码枪扫描带字母的条型码,但如果当前input焦点处是中文输入法就无法触发回车事件,因为中文输入法是输入一个整体才会键入内容,所以就不能监听到结束再执行动作了。所以需要给用户提示,及时切换输入法。

通过JQ判断input当前输入法是中文还是英文模式:

<input name="zc_code" id="zc_code" type="text" value="" class="zc_code" maxlength="15"/>

<script>
function get_shurufa(){
    $('#zc_code').on('input', function() {
        if ($(this).prop('comStart')) return;  //中文输入过程中不截断
        //console.log('当前输入:' + $(this).val());
    }).on('compositionstart', function(){
        $(this).prop('comStart', true);
        //console.log('中文输入:开始->' + $(this).val());
        
        $("#tishi_str").html('请将输入法切换为“英文”模式!')
        $("#tishi").css("background","#FF0000");
        $("#tishi").fadeIn().fadeOut().fadeIn()
        $("#zc_code").val('')
        return false;
    }).on('compositionend', function(){
        $(this).prop('comStart', false);
        //console.log('中文输入:结束->'  + $(this).val());
        
        $("#tishi_str").html('请将输入法切换为“英文”模式!')
        $("#tishi").css("background","#FF0000");
        $("#tishi").fadeIn().fadeOut().fadeIn()
        $("#zc_code").val('')
        return false;
    });
}

$(document).ready(function(){
    get_shurufa()
});
</script>


推荐的文章
# 发表我的评论
  /     /  
# 最近评论
暂时还没有评论,要不要说点什么?
  Ads by Google
  联系博主
Hello,本博客系统采用PHP和MySql开发,程序开发完全是因为个人爱好,是自己纯手写PHP源代码,未采用任何PHP框架!
QQ:858353007   微信号:lileihot123
网站地图
会员服务
关于我们
QQ:858353007
 
广告服务
加我微信
移动端访问
 
 
Copyright © 2014- 2024 www.mdaima.com All Rights Reserved.
李雷博客,专注PHP经验、PHP教程及PHP源代码开源下载分享的PHP博客!   ICP备案号:京ICP备10202169号-4