jq 监听input 输入的是英文还是汉文

 s
 sh
 shu
 shu'r
 shu'ru
 shu'ru'y
 shu'ru'yi
 shu'ru'yi'g
 shu'ru'yi'ge
 shu'ru'yi'ge'z
 shu'ru'yi'ge'zi

 输入一个字

输入一个字  监听input框事件 触发了这么多次,但是我只是打5个字

/** 
 * 预载入
*/
window.onload = function () {
	var doing = false;
	var doSomething = function (e) {
		txt = $('#saytext').val();
		console.log(txt);
		leng = getByteLen(txt);
		mydate = new Date();
		times = mydate.getSeconds();
		obj = [leng, times];
		obj = JSON.stringify(obj);
		if ($.cookie("obj") != null) {
			last_leng = JSON.parse($.cookie("obj"))[0];
			last_times = JSON.parse($.cookie("obj"))[1];
			if (Math.abs(leng - last_leng) != 6) {
				return false;
			}
		}
		if (leng >= 10) {
			$.ajax({
				url: "" + URLROOT + "/user/work/anticipation",
				type: 'POST',
				data: {
					message: txt,
					clientid: clientid
				},
				success: function (data) {
					obj = [leng, times];
					obj = JSON.stringify(obj);
					// console.log(123456789);
					$.cookie('obj', obj);
				}
			})
		}
	}

	document.getElementById('saytext').addEventListener('compositionstart', function (e) {  //compositionstart禁止使用中文输入法
		doing = true;
	}, false);
	document.getElementById('saytext').addEventListener('input', function (e) {
		if (!doing) {
			doSomething();
		}
	}, false);

	document.getElementById('saytext').addEventListener('compositionend', function (e) {//compositionstart禁止使用英文
		doing = false;
		doSomething();
	}, false);
}


打汉字只输入一次 

猜你喜欢

转载自blog.csdn.net/joker6295/article/details/85322914