<html>
<head>
<script language="javascript">
<!--
function isnumber(form)
{
var mylen=form.chn.value.length
var str=form.chn.value
var i,chick=true for(i=0;i<mylen;i++)
{
if( (str.charAt(i)<"0") || (str.charAt(i)>"9") )
{
chick=false
break;
}
} return chick;
}function numandsung(form)
{
var str=form.chn.value
if(isnumber(form))
{
if((str<0)||(str>100))
alert("分数的输入范围是从零到一百");
else
alert("已经成功输送");
}
else
alert("分数类不可以输入字符串,请确认");
}
//-->
</script>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head><body bgcolor="#FFFFFF" text="#000000">
<form name="my_form">
<h2>
姓名:<input type="text" name="name" size=10 maxlength=10><p>
语文:<input type="text" name="chn" size=3 maxlength=3><p>
</h2>
<input type="button" value="确认输入" onClick="javascript: numandsung(this.form)">
</form>
</body>
</html>
<head>
<script language="javascript">
<!--
function isnumber(form)
{
var mylen=form.chn.value.length
var str=form.chn.value
var i,chick=true for(i=0;i<mylen;i++)
{
if( (str.charAt(i)<"0") || (str.charAt(i)>"9") )
{
chick=false
break;
}
} return chick;
}function numandsung(form)
{
var str=form.chn.value
if(isnumber(form))
{
if((str<0)||(str>100))
alert("分数的输入范围是从零到一百");
else
alert("已经成功输送");
}
else
alert("分数类不可以输入字符串,请确认");
}
//-->
</script>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head><body bgcolor="#FFFFFF" text="#000000">
<form name="my_form">
<h2>
姓名:<input type="text" name="name" size=10 maxlength=10><p>
语文:<input type="text" name="chn" size=3 maxlength=3><p>
</h2>
<input type="button" value="确认输入" onClick="javascript: numandsung(this.form)">
</form>
</body>
</html>
解决方案 »
- document.body.getElementsByTagName("A")获取相对连接问题
- 求一正则表达式
- 我想实现某DIV下,每一个链接的字体颜色随机显示
- 一个getElementsByName的问题
- javascript中同步问题怎么解决!!!
- 请高手急救!!——如何在客户端判断上传文件大小
- 高分:那位高手有用脚本写的报表表单的源码?/
- jq = jQuery.noConflict();和jQuery.noConflict();
- 谁能解我燃眉之急!给分!关于一个Image做的button事件!Help me!!!!!!
- 如何实现图片下载完成的监测?(当然是用javascript)
- Text框的属性方法 -- 还有什么?
- js与xml的问题
如果你要允许 84.5,92.5之类的分数的话,用 var score=/^((\d{1,2}(\.5)?)|100)$/;
去代替原来的score变量即可<html>
<head>
<script language="javascript">
function checkdata(){
var score=/^(\d{1,2}|100)$/;
//var score=/^((\d{1,2}(\.5)?)|100)$/; //请去掉注释,如果允许出现半分的话
if (!score.test(document.my_form.chn.value)) {
alert("请输入一个0-100的整数")
}else{
alert("输入正确")
}
}
</script>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<form name="my_form">
<h2>
姓名:<input type="text" name="name" size=10 maxlength=10><p>
语文:<input type="text" name="chn" size=4 maxlength=4><p>
</h2>
<input type="button" value="确认输入" onClick="javascript:checkdata()">
</form>
</body>
</html>