日期:2014-05-16  浏览次数:20454 次

JavaScript 中 typeof 的疑难问题!!!!!!!!!!!!!!!!!!!!!
(问题一)

在   JSP   页面中     <td> <input   type=text   name= "num "   size= "25 "> <%=value%> </td>

onsubmit= "return   testCheck(this.num.value)   this   就是这个text所在的form

假设在JSP   <%%> 代码段中     int   value;   或者   String   value;

但是   如果在JS中   我做   typeof   测试   出来永远是   string  

如果改成     <%=Interge.paseInt(value)%>  

function   testCheck(str){
if(typeof(str)== "string ")
                      alert( "string ");
}

我就是想问     JSP中     <%=x%>     传入   JS方法做   typeof   判断   如何做的

(问题二)

如果   用户想输入   小数点   那该怎么办?     比如   123.12     (光判断数字   肯定不行)
因为   js中   只有   number

------解决方案--------------------
if(!str.match(/^([1-9]\d*|0)(\.\d+)?$/))

------解决方案--------------------
function testCheck(str){
try{
str=parseFloat(str);
}
catch(e)
{
alert(e);
}
if(typeof(str)== "string ")
alert( "string ");
}
------解决方案--------------------
typeOf()一般用来判断“undefined”的
js中因为交互过程中数据用流传输的,所以解析到页面都是字符串的
数据类型校验用正则才好~~~