通过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>
推荐的文章
随手记
PHP经验分享
- ● MySQLSUM在没有符合查询条件时返回结果为空的处理办法
- ● 如何开启PHP8的JIT提升运行速度
- ● 钉钉API接口-用PHP+Curl实现获取用户信息
- ● 钉钉API接口-用PHP+Curl实现获取应用Access_Token
- ● 在PHP中使用CURL,“撩”服务器只需几行——phpcurl详细解析和常见大坑
- ● MySQLInnodb并发涉及参数说明
- ● mysql参数调优之innodb_thread_concurrency、innodb_concurrency_tickets合理的使用cpu性能
- ● PHP用fsockopen检测指定IP端口是否开启可用
- ● PHP用socket检测服务器IP端口是否开放?代码示例
- ● GatewayWorker报错:Waring:Events::onMessageisnotcallable