`
michelecindy
  • 浏览: 169047 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

数字翻译成英文(进入后会提示你是否取消,要点否才能显示源代码)

    博客分类:
  • jsp
UP 
阅读更多
请输入一个0到999,999,999之间的数字
数字 
英文翻译 

实现代码:


<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>数字翻译成英文</title>
<LINK href=news.css rel=stylesheet>
</head>
<SCRIPT language=JavaScript>
var currentpos,timer;

function initialize()
{
timer=setInterval("scrollwindow()",50);
}
function sc(){
clearInterval(timer);
}
function scrollwindow()
{
currentpos=document.body.scrollTop;
window.scroll(0,++currentpos);
if (currentpos != document.body.scrollTop)
sc();
}
document.onmousedown=sc
document.ondblclick=initialize
</script>
<body topmargin="0" marginheight="0">
<table width="750" border="0" cellspacing="0" cellpadding="0" align="center" height="18">
  <tr> 
    <td height="25" class="unnamed1" background="images/logo_03.gif"><font color="#FFFFFF"> 
         </font><font color="#FFFFFF"><span class=a> 
      <script language=JavaScript class=a> 
today=new Date();
var hours = today.getHours();
var minutes = today.getMinutes();
var seconds = today.getSeconds();
var timeValue = "<FONT COLOR=#FFFFFF>" + ((hours >12) ? hours -12 :hours); timeValue += ((minutes < 10) ? "<BLINK><FONT =black>:</FONT></BLINK>0" : "<BLINK><FONT COLOR=#FFFFFF>:</FONT></black>") + minutes+"</FONT></FONT>";
timeValue += (hours >= 12) ? "<FONT COLOR=#FFFFFF>PM</FONT>" : "<FONT COLOR=#FFFFFF>AM</FONT>";
function initArray(){
this.length=initArray.arguments.length
for(var i=0;i<this.length;i++)
this[i+1]=initArray.arguments[i]  }
var d=new initArray("<font color=#FFFFFF>星期日","<font color=#FFFFFF>星期一","<font color=#FFFFFF>星期二","<font color=#FFFFFF>星期三","<font color=#FFFFFF>星期四","<font color=#FFFFFF>星期五","<font color=red>星期六"); document.write("<font color=#FFFFFF>",today.getYear(),"<font color=#FFFFFF>年","<font color=>",today.getMonth()+1,"<font color=>月","<font color=#FFFFFF>",today.getDate(),"<font color=#FFFFFF>日 </FONT>",d[today.getDay()+1]," ",timeValue);  //-->
</script>
    </span></font></td><td height="25" class="unnamed1" background="images/logo_03.gif" align="right"><font color="#FFFFFF">&nbsp;&nbsp;</font></td>
  </tr>
</table>

<table width="750" border="0" cellspacing="0" cellpadding="0" align="center">
  <tr> 
	<td>&nbsp;</td>
  </tr>
</table>

<table border="0" style="border-collapse: collapse" width="750" align=center cellspacing="1" cellpadding="0" >
<tr>
<td width="100%">
<table border="0" width="100%" cellspacing="0" cellpadding="0">
<tr>
<td width="95%" align="middle" valign="top">
<table border="0" width="100%" cellpadding="0" cellspacing="0">
<tr>
<td width="69%" align="middle" valign="top" bgcolor="">
                        <table border="1" cellpadding="0" cellspacing="0" width="100%" align="center" bordercolor="#AECAAE">
                          <tr> 
                            <td width="100%" align=center style="font-size:18px" height="60" valign="bottom" bordercolor="#FFFFFF"> 
                              <strong><font face="楷体_GB2312" size="5" color=#003399><b>数字翻译成英文<br>
                        </b></font></strong></td>
                    </tr>
                    <tr> 
                            <td width="100%" align=center bordercolor="#FFFFFF"> 
                              <hr width="100%" align="center" noshade size="1">
                      </td>
                    </tr>
 
                    <tr> 
                            <td width="100%" align=center style="font-size:9pt" bordercolor="#FFFFFF">&nbsp;</td>
                    </tr>
                    <tr> 
                            <td width="100%"  align="center" bordercolor="#FFFFFF"> 
                              <table width="98%" border="0" cellspacing="0" cellpadding="0" align="center" style="TABLE-LAYOUT: fixed">
                          <tr> 
                            <td width="100%" align=center> </td>
                          </tr>
                          <tr> 
                            <td style="WORD-WRAP: break-word"><font class=news><br>
                              <P align=center>
<SCRIPT language=JavaScript>
<!-- Begin
var n = "";
function validate(input) {
if (input.length == 0) {
alert ('请输入一个数字');
document.myform.textver.value = "";
return true;
}
else convert(input);
}
function d1(x) { // single digit terms
switch(x) {
case '0': n= ""; break;
case '1': n= " One "; break;
case '2': n= " Two "; break;
case '3': n= " Three "; break;
case '4': n= " Four "; break;
case '5': n= " Five "; break;
case '6': n= " Six "; break;
case '7': n= " Seven "; break;
case '8': n= " Eight "; break;
case '9': n= " Nine "; break;
default: n = "Not a Number";
}
return n;
}
function d2(x) { // 10x digit terms
switch(x) {
case '0': n= ""; break;
case '1': n= ""; break;
case '2': n= " Twenty "; break;
case '3': n= " Thirty "; break;
case '4': n= " Forty "; break;
case '5': n= " Fifty "; break;
case '6': n= " Sixty "; break;
case '7': n= " Seventy "; break;
case '8': n= " Eighty "; break;
case '9': n= " Ninety "; break;
default: n = "Not a Number";
}
return n;
}
function d3(x) { // teen digit terms
switch(x) {
case '0': n= " Ten "; break;
case '1': n= " Eleven "; break;
case '2': n= " Twelve "; break;
case '3': n= " Thirteen "; break;
case '4': n= " Fourteen "; break;
case '5': n= " Fifteen "; break;
case '6': n= " Sixteen "; break;
case '7': n= " Seventeen "; break;
case '8': n= " Eighteen "; break;
case '9': n= " Nineteen "; break;
default: n=  "Not a Number";
}
return n;
}
function convert(input) {
var inputlength = input.length;
var x = 0;
var teen1 = "";
var teen2 = "";
var teen3 = "";
var numName = "";
var invalidNum = "";
var a1 = ""; // for insertion of million, thousand, hundred 
var a2 = "";
var a3 = "";
var a4 = "";
var a5 = "";
digit = new Array(inputlength); // stores output
for (i = 0; i < inputlength; i++)  {
// puts digits into array
digit[inputlength - i] = input.charAt(i)};
store = new Array(9); // store output
for (i = 0; i < inputlength; i++) {
x= inputlength - i;
switch (x) { // assign text to each digit
case x=9: d1(digit[x]); store[x] = n; break;
case x=8: if (digit[x] == "1") {teen3 = "yes"}
          else {teen3 = ""}; d2(digit[x]); store[x] = n; break;
case x=7: if (teen3 == "yes") {teen3 = ""; d3(digit[x])}
          else {d1(digit[x])}; store[x] = n; break;
case x=6: d1(digit[x]); store[x] = n; break;
case x=5: if (digit[x] == "1") {teen2 = "yes"}
          else {teen2 = ""}; d2(digit[x]); store[x] = n; break;
case x=4: if (teen2 == "yes") {teen2 = ""; d3(digit[x])}    
          else {d1(digit[x])}; store[x] = n; break;
case x=3: d1(digit[x]); store[x] = n; break;
case x=2: if (digit[x] == "1") {teen1 = "yes"}
          else {teen1 = ""}; d2(digit[x]); store[x] = n; break;
case x=1: if (teen1 == "yes") {teen1 = "";d3(digit[x])}     
          else {d1(digit[x])}; store[x] = n; break;
}
if (store[x] == "Not a Number"){invalidNum = "yes"};
switch (inputlength){
case 1:   store[2] = ""; 
case 2:   store[3] = ""; 
case 3:   store[4] = ""; 
case 4:   store[5] = "";
case 5:   store[6] = "";
case 6:   store[7] = "";
case 7:   store[8] = "";
case 8:   store[9] = "";
}
if (store[9] != "") { a1 =" Hundred, "} else {a1 = ""};
if ((store[9] != "")||(store[8] != "")||(store[7] != ""))
{ a2 =" Million, "} else {a2 = ""};
if (store[6] != "") { a3 =" Hundred "} else {a3 = ""};
if ((store[6] != "")||(store[5] != "")||(store[4] != ""))
{ a4 =" Thousand, "} else {a4 = ""};
if (store[3] != "") { a5 =" Hundred "} else {a5 = ""};
}
// add up text, cancel if invalid input found
if (invalidNum == "yes"){numName = "对不起,你输入的不是数字!"}
else {
numName =  store[9] + a1 + store[8] + store[7] 
+ a2 + store[6] + a3 + store[5] + store[4] 
+ a4 + store[3] + a5 + store[2] + store[1];
}
store[1] = ""; store[2] = ""; store[3] = ""; 
store[4] = ""; store[5] = ""; store[6] = "";
store[7] = ""; store[8] = ""; store[9] = "";
if (numName == ""){numName = "Zero"};
document.myform.textver.value = numName;
return true;
}
//  End -->
</SCRIPT>
<FONT color=#dc143c size=4>&nbsp;请输入一个0到999,999,999之间的数字 </FONT></P>
<DIV align=center>
<FORM name=myform>
<TABLE border=0>
<TBODY>
<TR>
<TD><FONT color=#dc143c size=4>数字</FONT></TD>
<TD><INPUT maxLength=9 size=9 name=numver><FONT color=#dc143c size=4> </FONT><INPUT onClick="return validate(document.myform.numver.value)" type=button value=翻译数字></TD></TR>
<TR>
<TD><FONT color=#dc143c size=4>英文翻译</FONT></TD>
<TD><INPUT maxLength=50 size=50 name=textver><FONT color=#dc143c size=4></FONT></TD></TR>
<TR>
<TD align=middle colSpan=2><FONT color=#dc143c size=4></FONT></TD></TR></TBODY></TABLE>
<P><BR>
</P>
</FORM></DIV><br>
                            </font></td>
                          </tr>
                        </table>
                      </td>
                    </tr>          
                  </table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>


<table width="750" border="0" cellspacing="0" cellpadding="0" align="center" bgcolor="ff9933">
<tr>
<td>
            
      <table width="750" border="0" cellspacing="0" cellpadding="0" bgcolor="#A7CCFA" align="center">
        <tr bgcolor="#EED9EE"> 
          <td width="20"> </td>
                
          <td  width="255" height="20"> 
            <!-- 发布人:<a href=userlist.asp?name=coolweb>coolweb</a> -->          </td>
                
          <td  width="214" height="20"></td>
                
          <td  width="168">&nbsp;</td>
                
          <td  width="91">&nbsp;</td>
</tr>
        <tr valign="top"> 
          <td width="20" height="1" bgcolor="ff9933"></td>
          <td width="469" height="1" colspan="2" bgcolor="ff9933"></td>
          <td width="259" height="1" colspan="2" bgcolor="ff9933"></td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics