javascript实现字符串反转

< html >

< head >
< script  language ="javascript" >
    
function  reverse()
    {
        
var  str = document.getElementById( " input " ).value;
        
var  a = str.split( '' );
        
var  result = new  Array();
        
while (a.length)
        {
            result.push(a.pop());
        }
        document.getElementById(
" result " ).innerHTML = result.join( '' );
    }
</ script >


< title > javascript </ title >

</ head >

< body >
    
< table >
    
< tr >
    
< td >< input  type ="textfield"  id ="input" /> = &gt; </ td >
    
< td >< div  id ="result" ></ div ></ td >
    
</ tr >
    
</ table >
    
< input  type ="button"  value ="reverse"  onclick ="reverse()" />
</ body >

</ html >

 

你可能感兴趣的:(JavaScript)