首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

JavaScript 中 typeof 的疑难有关问题!

2012-02-10 
JavaScript 中 typeof 的疑难问题!!!!!!!!!!!!!!!!!!!!!(问题一)在JSP页面中tdinputtypetextname nu

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中因为交互过程中数据用流传输的,所以解析到页面都是字符串的
数据类型校验用正则才好~~~

热点排行