-
Notifications
You must be signed in to change notification settings - Fork 797
/
index.html
133 lines (126 loc) · 3.93 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta charset="utf-8"/>
<title>汉字拼音互转示例</title>
<style type="text/css">
body{font-family: 'Microsoft Yahei'; font-size: 16px;}
* {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
input[type="text"] {
height: 34px;
padding: 6px 12px;
font-size: 14px;
line-height: 1.42857143;
color: #555;
background-color: #fff;
background-image: none;
border: 1px solid #ccc;
border-radius: 4px;
box-shadow: inset 0 1px 1px rgba(0,0,0,.075);
-webkit-transition: border-color ease-in-out .15s,-webkit-box-shadow ease-in-out .15s;
transition: border-color ease-in-out .15s,box-shadow ease-in-out .15s;
}
input[type="text"]:focus {
border-color: #66afe9;
outline: 0;
-webkit-box-shadow: inset 0 1px 1px rgba(0,0,0,.075),0 0 8px rgba(102,175,233,.6);
box-shadow: inset 0 1px 1px rgba(0,0,0,.075),0 0 8px rgba(102,175,233,.6);
}
#test {width: 300px;}
h2 {
background-color: #3199E4;
color: white;
padding: 2px 8px;
border-radius: 5px;
font-size: 30px;
line-height: 1.5;
text-shadow: 1px 1px 1px black;
width: 800px;
}
h2 > span {
color: #B10000;
font-size: 0.8em;
}
#test {margin-top: 10px;}
.loading-tip{color: #00960A;margin-bottom: 10px;}
.container {
width: 1024px;
margin: 20px auto;
}
</style>
</head>
<body>
<div class="container">
<a href="http://blog.haoji.me/pinyinjs.html" target="_blank">返回原文</a>
<a href="http://github.com/sxei/pinyinjs/" target="_blank">github地址</a>
<h2>汉字转拼音</h2>
<div>
<span>输出类型:</span>
<label><input type="radio" name="pinyin_type" value="0" checked/>带声调拼音</label>
<label><input type="radio" name="pinyin_type" value="1"/>不带声调拼音</label>
<label><input type="radio" name="pinyin_type" value="2"/>拼音首字母</label>
</div>
<div>
<span>多音字:</span>
<label><input type="checkbox" name="polyphone"/>简单支持多音字</label>
<span style="color: #9E9E9E;">(支持多音字仅仅是将所有可能的组合列举出来,要做到准确识别多音字还需非常完善的词库)</span>
</div>
<input type="text" id="test" value="大中国" placeholder="请随便输入一些中文"/>
<h3>转换结果:</h3>
<div id="result"></div>
<h2>带词库、“准确”识别多音字示例</span></h2>
<p>由于词库文件较大,请单独<a href="polyphone.html" target="_blank">移步至这里查看支持多音字示例</a>。</p>
<h2>JS实现简单的拼音输入法</h2>
<p>JS实现的输入法请单独移步至<a href="simple-input-method.html" target="_blank">JS实现简单的拼音输入法</a>。</p>
</div>
<script type="text/javascript" src="dict/pinyin_dict_withtone.js"></script>
<script type="text/javascript" src="pinyinUtil.js"></script>
<script type="text/javascript">
function getPinyin()
{
var value = document.getElementById('test').value;
var type = document.querySelector('[name="pinyin_type"]:checked').value;
var polyphone = document.querySelector('[name="polyphone"]').checked;
var result = '';
if(value)
{
switch(type)
{
case '0': result = pinyinUtil.getPinyin(value, ' ', true, polyphone); break;
case '1': result = pinyinUtil.getPinyin(value, ' ', false, polyphone); break;
case '2': result = pinyinUtil.getFirstLetter(value, polyphone); break;
default: break;
}
}
var html = result;
if(result instanceof Array)
{
html = '<ol>';
result.forEach(function(val)
{
html += '<li>'+val+'</li>';
});
html += '</ol>';
}
document.getElementById('result').innerHTML = html;
}
document.getElementById('test').addEventListener('input', getPinyin);
document.getElementsByName('polyphone')[0].addEventListener('change', function(e)
{
getPinyin();
});
document.addEventListener('change', function(e)
{
if(e.target.name === 'pinyin_type')
{
getPinyin();
}
});
getPinyin();
</script>
</body>
</html>