forked from aliceui/aliceui.github.io
-
Notifications
You must be signed in to change notification settings - Fork 283
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
53 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
./plugins/AntBuild/tmp/ | ||
*.swp | ||
*.D_Store | ||
*.D_Store | ||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>localStorage</title> | ||
<style type="text/css"> | ||
body{padding:30px;} | ||
p{margin-bottom:15px;} | ||
#tips small{font-size:12px;color:#999;} | ||
</style> | ||
</head> | ||
|
||
<body> | ||
|
||
<div id="wrapper" class="single"> | ||
|
||
<h3>是否为中文?</h3> | ||
<input id="words" placeholder="请输入中文字符"> | ||
<p id="tips"></p> | ||
|
||
<script type="text/javascript"> | ||
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> | ||
|
||
</div><!-- #wrapper --> | ||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
### 检测文字是否为中文 | ||
|
||
```js | ||
var isChinese = function(word) { | ||
return /[\u4E00-\uFA29]+|[\uE7C7-\uE7F3]+/.test(word) | ||
} | ||
|
||
isChinese('汉'); // true | ||
``` |