var reverse = function (x) {
x = '' + x;
var ret = '';
for (var i in x) {
ret = x[i] + ret;
}
ret = ret.replace(/[^d]/g, '')
if (-1 * x > 0) {
ret = -ret;
}
if (ret < -Math.pow(2, 31) || ret > Math.pow(2, 31) - 1) {
ret = 0;
}
return +ret;
};
或者low(me)
window.onload=function(){
function reverse(x) {
if(x<-(Math.pow(2,31))){return 0;}
if(x>(Math.pow(2,31)-1)){return 0;}
var zero=0;
var reverseNumber=[];
var nstring=Math.abs(x)+"";
var result='';
var fushu=false;
var resultNumber=0;
var abs=Math.abs(x);
if(abs>x){fushu=true;}else{fushu=false;}
reverseNumber=nstring.split("");
zero=reverseNumber.length;
for(var i=reverseNumber.length-1;i>0;i--){
if(parseInt(reverseNumber[i])==0){
zero=i;
}else{
break;
}
}
result=reverseNumber.slice(0,zero+1);
var strings=result.reverse();
resultNumber=strings.join("")-0
if(!fushu){ resultNumber=resultNumber;}else{resultNumber=-resultNumber;}
if(resultNumber<-(Math.pow(2,31))){return 0;}
if(resultNumber>(Math.pow(2,31)-1)){return 0;}
};
reverse(1534236469);
}