代码拉取完成,页面将自动刷新
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>获取汉字首字母 js 插件使用</title>
</head>
<body>
<div>
<div>获取字符串第一个字符的首字母</div></div>
<input type="text" onblur="getInitial1(this.value)">
<button>获取首字母</button>
<div id="txt1"></div>
<div style="font-size: 12px; color: #999; margin-top: 20px;">多个字母开头的多音字会显示多个字母</div>
</div>
<div>
<div>获取字符串每个字符的首字母</div></div>
<input type="text" onblur="getInitial2(this.value)">
<button>获取首字母</button>
<div id="txt2"></div>
<div style="font-size: 12px; color: #999; margin-top: 20px;">多个字母开头的多音字会显示多个字母</div>
</div>
<div>
<div>获取字符串拼音</div></div>
<input type="text" onblur="getInitial3(this.value)">
<button>获取首字母</button>
<div id="txt3"></div>
<div style="font-size: 12px; color: #999; margin-top: 20px;">多个字母开头的多音字会显示多个字母</div>
</div>
<script src="./convert-pinyin.js"></script>
<script>
// 返回所有字符的首字母
function getInitial1(str) {
let py = getChineseStrPY(str);
console.log(py);
document.getElementById('txt1').textContent = py;
}
function getInitial2(str) {
// 返回第一个字符的首字母
let py = getChineseStrPY(str, 'first');
console.log(py);
document.getElementById('txt2').textContent = py;
}
// 返回每一个字符的拼音全拼
function getInitial3(str) {
let py = getChineseStrPY(str, 'all');
console.log(py);
document.getElementById('txt3').textContent = py;
}
</script>
</body>
</html>
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。