1. 程式人生 > >input中文輸入不打斷

input中文輸入不打斷

rim pos 輸入 substr inpu ext star this turn

//優惠券標題
    $(‘#CouponTitle‘).on(‘input‘, function() {
        if($(this).prop(‘comStart‘)) return; // 中文輸入過程中不截斷
        CouponTitle = $(this).val().trim();
        if(CouponTitle.length <= 9) {
            $(this).next().html(CouponTitle.length + "/9");
            $(".CouponTitleCard").html(CouponTitle).show();
        } 
else { CouponTitle = CouponTitle.substr(0, 9); $(this).val(CouponTitle); $(this).next().html(9 + "/9"); $(".CouponTitleCard").html(CouponTitle).show(); $(this).blur(); } }).on(‘compositionstart‘, function() { $(this).prop(‘comStart‘, true
); //中文輸入開始 }).on(‘compositionend‘, function() { $(this).prop(‘comStart‘, false); //中文輸入結束 CouponTitle = $(this).val().trim(); if(CouponTitle.length <= 9) { $(this).next().html(CouponTitle.length + "/9"); $(".CouponTitleCard").html(CouponTitle).show(); }
else { CouponTitle = CouponTitle.substr(0, 9); $(this).val(CouponTitle); $(this).next().html(9 + "/9"); $(".CouponTitleCard").html(CouponTitle).show(); $(this).blur(); } });

input中文輸入不打斷