AJAX 實現的漢字轉換為拼音一

來源:互聯網
上載者:User

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>無標題文檔</title>
<script type="text/javascript">

var xmlHttp=false;
try{
xmlHttp=new XMLHttpRequest();
}catch(e){
try{
   xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}catch(e2){
   try{
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
   }catch(e3){
    xmlHttp=false;
   }
}
}

function call()
{
var hanzi=document.getElementById("hanzi").value;
if(hanzi==null||hanzi=="")
return ;
var url="pingyin.php?hanzi="+hanzi;
xmlHttp.open("GET",url,true);
xmlHttp.onreadystatechange=chang_to_pingyin1;
xmlHttp.send();
}

function chang_to_pingyin1()
{
if(xmlHttp.readystate==4)
   {
   if(xmlHttp.status==200)
    {
     var pingyin1=xmlHttp.responseText;
     document.getElementById("1").value=pingyin1;
    }
    else
     alert("The status is "+xmlHttp.status);
   }
}

function call2()
{
var hanzi=document.getElementById("hanzi2").value;
if(hanzi==null||hanzi=="")
return ;
var url="pingyin.php?hanzi="+hanzi;
xmlHttp.open("GET",url,true);
xmlHttp.onreadystatechange=chang_to_pingyin2;
xmlHttp.send();
}

function chang_to_pingyin2()
{
if(xmlHttp.readystate==4)
   {
   if(xmlHttp.status==200)
    {
     var pingyin2=xmlHttp.responseText;
     document.getElementById("2").value=pingyin2;
    }
    else
     alert("The status is "+xmlHttp.status);
   }
}
function call3()
{
var hanzi=document.getElementById("hanzi3").value;
if(hanzi==null||hanzi=="")
return ;
var url="pingyin.php?hanzi="+hanzi;
xmlHttp.open("GET",url,true);
xmlHttp.onreadystatechange=chang_to_pingyin3;
xmlHttp.send();
}

function chang_to_pingyin3()
{
if(xmlHttp.readystate==4)
   {
   if(xmlHttp.status==200)
    {
     var pingyin3=xmlHttp.responseText;
     document.getElementById("3").value=pingyin3;
    }
    else
     alert("The status is "+xmlHttp.status);
   }
}
function call4()
{
var hanzi=document.getElementById("hanzi4").value;
if(hanzi==null||hanzi=="")
return ;
var url="pingyin.php?hanzi="+hanzi;
xmlHttp.open("GET",url,true);
xmlHttp.onreadystatechange=chang_to_pingyin4;
xmlHttp.send();
}

function chang_to_pingyin4()
{
if(xmlHttp.readystate==4)
   {
   if(xmlHttp.status==200)
    {
     var pingyin4=xmlHttp.responseText;
     document.getElementById("4").value=pingyin4;

    }
    else
     alert("The status is "+xmlHttp.status);
   }
}

</script>
</head>

<body>

輸入漢字:
<input name="hanzi" type="text" id="hanzi" onKeyup="return call();"/>

<input name="hanzi2" type="text" id="hanzi2"  onKeyup="return call2();"/>

<input name="hanzi3" type="text" id="hanzi3" onKeyup="return call3();"/>

<input name="hanzi4" type="text" id="hanzi4" onKeyup="return call4();"/>
<br />
<input name="1" type="hidden" id="1"  onpropertychange="javascript:document.getElementById('pingyins').value=document.getElementById('1').value+document.getElementById('2').value+document.getElementById('3').value+document.getElementById('4').value;"/>

<input name="2" type="hidden" id="2" onpropertychange="javascript:document.getElementById('pingyins').value=document.getElementById('1').value+document.getElementById('2').value+document.getElementById('3').value+document.getElementById('4').value;"/>
 <input name="3" type="hidden" id="3" onpropertychange="javascript:document.getElementById('pingyins').value=document.getElementById('1').value+document.getElementById('2').value+document.getElementById('3').value+document.getElementById('4').value;"/>
 <input name="4" type="hidden" id="4" onpropertychange="javascript:document.getElementById('pingyins').value=document.getElementById('1').value+document.getElementById('2').value+document.getElementById('3').value+document.getElementById('4').value;"/><br />
 拼音助記:
 <input name="pingyins" type="text" id="pingyins"/>
</body>
</html>

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.