1 <!DOCTYPE HTML>2 <HTML>3 <Head>4 <title>Xxx</title>5 </Head>6 <Body>7 <inputID= "Test"type= "text">8 <DivID= "Display"></Div>9 <Script>Ten //support to 1~9999 One functionInt2zh (arg_num) { A varNum=Arg_num; - vararr1= ['0','a','two','three','Four','Five','Six','Seven','Eight','Nine'], arr2= ["', '10', 'Hundred', 'thousand', 'million']; - varI= 0, digit, result= []; the while(num) { - Digit=Num% Ten; - if(Digit=== 0){ - if(Result.length=== 0) { + Num=Math.floor (Num/ Ten); - I++; + Continue; A } at if('0' ==Result[result.length- 1]) { - Num=Math.floor (Num/ Ten); - I++; - Continue; - } - Result.push ('0'); in }Else{ - Result.push (Arr2[i]); to Result.push (Arr1[digit]); + } - Num=Math.floor (Num/ Ten); the I++; * } $ if(Arg_num< - &&Arg_num>= Ten){Panax Notoginseng Result.splice (Result.length- 1, 1); - } the returnResult.reverse (). Join (""); + } A document.getElementById ('Test'). AddEventListener ("input", function(){ the varVal= This. Value; + varR=Int2zh (val); - display.innerhtml=R; $ },false); $ </Script> - </Body> - </HTML>
Arabic numerals converted into Chinese numerals (support 1~9999)