失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > 鸡肋功能2————将汉字转化为拼音(带声调)

鸡肋功能2————将汉字转化为拼音(带声调)

时间:2024-05-01 04:57:35

相关推荐

鸡肋功能2————将汉字转化为拼音(带声调)

根据上一篇博客,继续是实现下一个功能,将汉字转化为拼音,要带声调。

需要用到的插件:/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':result = pinyinUtil.getPinyin(value, ' ', false, polyphone);break;case '2':result = pinyinUtil.getFirstLetter(value, polyphone);break;default:break;}}$('.pinyin').text('拼音:'+result)}

每次更换汉字的时候执行getPinyin(当前汉字)这个方法即可。

如果觉得《鸡肋功能2————将汉字转化为拼音(带声调)》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。