zoukankan      html  css  js  c++  java
  • 输入法的中文输入状态下 监听中文字符的提示

        var cpLock = true;
        $('.yx_search_inptfn').on({
            compositionstart: function () {//中文输入开始
                cpLock = false;
            },
            compositionupdate:function(){
            },
            compositionend: function () {//中文输入结束
                cpLock = true;
            },
            input: function () {//input框中的值发生变化
                setTimeout(function(){
                    if (cpLock){
                        var thisval=$('.yx_search_inptfn').val();
                        thisval=thisval.replace(/^s*/,'');
                        thisval=thisval.replace(/s*$/,'');
                        $('.yx_search_inptfn').val(thisval);
                        if(thisval!=''){
                            $('.yx_search_btnfn2').html('搜索');
                        }else{
                            $('.yx_search_btnfn2').html('取消');
                        }
                    }
                },1)
            }
        })

     输入中文的时候 会先出现compositionstart,开关会先关掉,关闭掉了input的实时监听。

    当输入中文,选择了要输入的中文情况后,compositionend触发,再出发input事件。但是这时候input还是false状态监听不了,要加settimeout,延迟1毫秒,先触发8 再触发7,先compositionend,把开关打开,在触发input结束,完美软键盘解决输入中文情况。

  • 相关阅读:
    [LeetCode] Rotate Image
    [LeetCode] Generate Parentheses
    pandas 使用总结
    ConfigParser 读写配置文件
    Cheat Sheet pyspark RDD(PySpark 速查表)
    python随机生成字符
    grep 命令
    hadoop 日常使用记录
    python 2 计算字符串 余弦相似度
    screen命令
  • 原文地址:https://www.cnblogs.com/gaidalou/p/10593667.html
Copyright © 2011-2022 走看看