数组元素判断类型

gmj_1019 2003-04-07 10:29:37
在1个form里有个数组。我想判断录入的数组元素的类型是否满足数字型?
请帮我写一下checkInput()里的内容。谢谢!
a.php
---------------------
<script language="javascript">
function checkInput()
{

}
</script>

<form name="form1" action="a.php" method="post" onsubmit="return checkInput();">
<?
for ($i=0;$i<10;$i++)
{
?>
<input type=text name=sl[] size=15 >

<?
}
?>
<input type=submit name="ok" value="ok">
</form>
...全文
119 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
indeed 2003-04-07
  • 打赏
  • 举报
回复
这样写,仔细看看
<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>
gmj_1019 2003-04-07
  • 打赏
  • 举报
回复
function fucCheckNUM(NUM)
{
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;
}
我这里有判断数字型的函数,但是,我怎么判断数组里的元素的类型?
sdliubo 2003-04-07
  • 打赏
  • 举报
回复
用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>

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧