用js脚本来写最好 因为php要到服务器端难证在form中添加 onclick="return checknumeric();"<script language="vbscript">
'===ZJ 校验函数===
'判断是否是数字
function checknumeric(obj)
if (obj.value <> "-" and obj.value <> "." and not Isnumeric(obj.value) and window.event.keycode<>9 and obj.value<>"" ) then
alert("请输入数字!")
obj.value=""
obj.focus
end if
end function</script>
'===ZJ 校验函数===
'判断是否是数字
function checknumeric(obj)
if (obj.value <> "-" and obj.value <> "." and not Isnumeric(obj.value) and window.event.keycode<>9 and obj.value<>"" ) then
alert("请输入数字!")
obj.value=""
obj.focus
end if
end function</script>
解决方案 »
- 循环table转换成div
- json格式的数据如何转移成php能用的变量呀?
- 怎样做一个真正的分页?
- 高手帮忙,PHP连接MYSQL的问题
- 请那位先生\小姐帮我看看这段php程序.为什么程序中$concent传入数据库的值是$concent而不能转为html(news.php另一部分)
- 请教一个问题:为什么程序在服务器上不能使用
- php不支持函数重载,怎么办?
- 问题??!!!
- 怎么用上传php发送带附件的e-mai.???
- Failed to create COM object `com.sun.star.ServiceManager': Server execution fail
- 死掉了,来人呀!
- 询问有关项目的行情:
{
var i,j,strTemp;
strTemp="0123456789";
if ( NUM.length== 0)
return 0
for (i=0;i<NUM.length;i++)
{
j=strTemp.indexOf(NUM.charAt(i));
if (j==-1)
{
//说明有字符不是数字
return 0;
}
}
//说明是数字
return 1;
}
我这里有判断数字型的函数,但是,我怎么判断数组里的元素的类型?
<script language="javascript">function IsDigit(cCheck)
{
return (('0'<=cCheck) && (cCheck<='9'));
}
function checkInput()
{
for(i=0;i<10;i++)
{
tmps1= document.form1.ss1[i].value;
if (tmps1 == "")
{
alert("第"+i+"个输入框不能为空!");
document.form1.ss1[i].focus();
return false;
}
for (nIndex=0; nIndex<tmps1.length; nIndex++)
{
cCheck = tmps1.charAt(nIndex);
if(!IsDigit(cCheck))
{
alert("第"+i+"个输入框必须是数字");
document.form1.ss1[i].focus();
return false;
}
}
}
}
</script>
<form name="form1" action="tt.php" method="post" onsubmit="return checkInput();">
<?
for ($i=0;$i<10;$i++)
{
?>
<input type=text name=sl[<?echo $i;?>] id=ss1 size=15 > <?
}
?>
<input type=submit name="ok" value="ok">
</form>