根据上一篇博客,继续是实现下一个功能,将汉字转化为拼音,要带声调。
需要用到的插件:https://download.csdn.net/download/impossible1994727/12628685
根据项目需求引入自己需要的js,我这里用了pinyin_dict_withtone.js和pinyinUtil.js。
抽离出自己需要的方法如下:
function getPinyin(value) {
// var value = document.getElementById('test').value;
// var type = document.querySelector('[name="pinyin_type"]:checked').value;
// var polyphone = document.querySelector('[name="polyphone"]').checked;
var type = '0', polyphone = true;
var result = '';
if (value) {
switch (type) {
case '0':
result = pinyinUtil.getPinyin(value, ' ', true, polyphone);
break;
case '1':