1. 程式人生 > >jQuery判斷輸入法和非輸入法輸入

jQuery判斷輸入法和非輸入法輸入

one 輸入法 中文輸入 console mst tar 方案 turn jquer

需求背景:

  頁面需要輸入完成後自動查詢。

解決方案:

$(‘input‘).on(‘input‘, function() {
    if ($(this).prop(‘comStart‘)) return;
    console.log(‘當前輸入:‘ + $(this).val());
}).on(‘compositionstart‘, function(){
    $(this).prop(‘comStart‘, true);
    console.log(‘中文輸入:開始->‘ + $(this).val());
}).on(‘compositionend‘, function(){
    $(this).prop(‘comStart‘, false);
    console.log(‘中文輸入:結束->‘  + $(this).val());
});

  

jQuery判斷輸入法和非輸入法輸入