js汉字转拼音代码,js实现汉字转拼音教程如下:
输入汉字
实现结果:生成对应汉字的拼音
js实现代码如下:
/**
* @act 涓枃杞嫾闊�
* @version 1.0
* @author youngxj
* @date 2018-04-18
* @url http://www.youngxj.cn
*/
function getPinyin(){
var value = document.getElementById('textareaCode_zw').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