在线中汉子转化成拼音代码

来源:https://www.sucaihuo.com/js/1572.html 2017-03-29 17:37浏览(744) 收藏

这是一款中文转换拼音的功能代码,不错的效果实用。适合给小孩教学,中年学拼音。
在线中汉子转化成拼音代码
分类:其它特效 难易:初级
查看演示 下载资源 下载积分: 20 积分
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();

	// 初始化简单的拼音输入法
	SimpleInputMethod.init('.test-input-method');
	document.querySelector('.loading-tip').innerHTML = 'JS加载完毕,现在你可以开始打字了!';
评论0
头像

系统已开启自动识别垃圾评论机制,识别到的自动封号,下载出错或者资源有问题请联系全栈客服QQ 1915635791

1 2