解决方案描述
核心JS: var isChinese = function(word) { return /[\u4E00-\uFA29]+|[\uE7C7-\uE7F3]+/.test(word) } isChinese('汉'); // true 本例实现: <script> var words = document.getElementById('words'), tips = document.getElementById('tips'), isChinese = function (word) { return /[\u4E00-\uFA29]+|[\uE7C7-\uE7F3]+/.test(word) } words.onkeyup = function () { var arr = [], msg = [], input = words.value for (var i = 0, len = input.length; i < len; i++) arr.push(input[i]) for (var i = 0, len = arr.length; i < len; i++) { !isChinese(arr[i]) && msg.push((i + 1) + '<small>(' + arr[i] + ')</small>') } if (msg.length) tips.innerHTML = '第' + msg.join('、') + '个字不是中文'; } </script>
实践出真知