要强制转换,数值到字符不可以自动转换
自动类型转换规则为:①(byte或short)opint→int
②(byte或short或int)oplong→long
③(byte或short或int或long)opfloat→float
④(byte或short或int或long或float)opdouble→double
⑤charopint→int
自动类型转换规则为:①(byte或short)opint→int
②(byte或short或int)oplong→long
③(byte或short或int或long)opfloat→float
④(byte或short或int或long或float)opdouble→double
⑤charopint→int
var mon=10;
if((string)mon.length()<2){
..........
}
或 if(string(mon).length<2){}这样我都试过都不行呀! 有什么方法请指点!
var strMon = mon + "";
alert(strMon.length);
alert(mon.toString().length);
var mon=10;
mon=mon+""; //数字->字符串的转化. JavaScript的类型转换很灵活的.
alert(mon.length);
if(mon.length<=2){alert('长度小于等于2')}
</script>
var i=100;
alert(i.toString().length);
太恶了吧?