The conversion of Chinese characters to Pinyin is realized by AJAX

Source: Internet
Author: User

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 "/>
<title> Untitled Document </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>

<body>

Enter Chinese characters:
<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/>
  Phonetic mnemonics:
 <input name= "Pingyins" type= "text" id= "Pingyins"/>
</body

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.