if(isNaN(value))
不是数字
else
是数字
不是数字
else
是数字
解决方案 »
- 全局变量?为什么?
- 来者有分,dtree 展开后的树,当点击任意一个你节点时如何禁止收缩子节点??
- onclick在firefox下无效
- style.display="" 是什么意思呢?
- 请问有没有办法用javascript方法控制表的单元格背景?100分!!!拜托各位了
- 求象marquee一样从右到左的源码,可以设开始的位置
- 在网页上报这个错,怎么更正啊!谢谢!
- 一个很弱智的问题:在javascript中,一个变量名怎样包含另一个变量名,如vbscript中可用 title_name"&i&"
- 正则表达式/.../i,最后那个i用来干什么的?
- jQuery问题:如何获得选择器结果集中某个元素的索引
- 十万火急!如何实现把文本框里的字符从右往左逐个删除?
- 关于javascript调用vbscript的问题?是否可以调用?
<HEAD>
<META name=VI60_defaultClientScript content=JavaScript>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<TITLE></TITLE>
<SCRIPT LANGUAGE=javascript>
<!--
function che() {
if (!isNaN(123)) {
window.alert("数字")
else
window.alert("不是数字")
}
}
//-->
</SCRIPT></HEAD>
<BODY>
<INPUT type="button" value="Button" id=button1 name=button1 onclick="che()"></BODY>
</HTML>
{
if (!isNaN(123))
window.alert("数字")
else
window.alert("不是数字")
}
这段程序是来判断表单填写的生日是否合法。谢谢!
function checkForm(theForm) {
if ((!theForm.dtBirthYearGet.value) && (!theForm.dtBirthMonthGet.value) && (!theForm.dtBirthDayGet.value)) {
if (!isNaN(theForm.dtBirthYearGet.value) && (!isNaN(theForm.dtBirthMonthGet.value) && (!isNaN(theForm.dtBirthDayGet.value)) {
if (((theForm.dtBirthYearGet.value <= 1900) || (theForm.dtBirthMonthGet.value >= 2002)) || ((theForm.dtBirthMonthGet.value <=1) || (theForm.dtBirthMonthGet.value >= 12)) || ((theForm.dtBirthDayGet.value <= 1) || (theForm.dtBirthDayGet.value >= 31))) {
window.alert ("您的生日填写有错误.");
theForm.dtBirthYearGet.focus();
return(false);
}
else
window.alert ("您的生日填写有错误.");
theForm.dtBirthYearGet.focus();
return(false);
}
}
}下面有一个这样的表单。
<form ...... name=form onsubmit="return checkForm(form)">
如果是的话,我试了一下
你的else没有指定正确位置,即根据就近原则它和最后一个if配对
所以不管你的if后面的条件是否为真,都会执行
window.alert ("您的生日填写有错误.");
theForm.dtBirthYearGet.focus();
return(false);
因为if 和else一样的
如果你有良好的编程习惯的话(缩进编辑,配对括号),你会很清楚
的发现问题所在。修改后如下(仅供参考)function checkForm(theForm)
{
if ((!theForm.dtBirthYearGet.value) && (!theForm.dtBirthMonthGet.value) && (!theForm.dtBirthDayGet.value))
{
if (!isNaN(theForm.dtBirthYearGet.value) && (!isNaN(theForm.dtBirthMonthGet.value) && (!isNaN(theForm.dtBirthDayGet.value))
{
if (((theForm.dtBirthYearGet.value <= 1900) ||(theForm.dtBirthMonthGet.value >= 2002)) || ((theForm.dtBirthMonthGet.value <=1) || (theForm.dtBirthMonthGet.value >= 12)) || ((theForm.dtBirthDayGet.value <= 1) || (theForm.dtBirthDayGet.value >= 31)))
{
window.alert ("您的生日填写有错误.");
theForm.dtBirthYearGet.focus();
return(false);
}
}
else
{
window.alert ("您的生日填写有错误.");
theForm.dtBirthYearGet.focus();
return(false);
}
}
}
{
window.alert(sMsg);
// set focus and highlight to the offending error
eSrc.focus();
eSrc.select();
}
function HandleKeyUp(eSrc)
{
// make sure they input a numeric value
// (in VBScript you'd use the IsNumeric() function)
var val = parseInt(eSrc.value);
if (isNaN(val))
{
return AbortEntry("Must be a number.", eSrc);
} // make sure the value is in range
if (val < 0 || val > 255)
{
return AbortEntry("Value must be between 0 and 255.", eSrc);
}
}
//--></SCRIPT>
Please enter a valid IP address
<FORM>
<INPUT TYPE="text" size=3 maxlength=3 ONKEYUP="HandleKeyUp(this)">.
<INPUT TYPE="text" size=3 maxlength=3 ONKEYUP="HandleKeyUp(this)">.
<INPUT TYPE="text" size=3 maxlength=3 ONKEYUP="HandleKeyUp(this)">.
<INPUT TYPE="text" size=3 maxlength=3 ONKEYUP="HandleKeyUp(this)">
</FORM>
{
if (string.charAt(i)>'9' && string.charAt(i)<'0') alert("is number");
else alert("is not number");
}try this!
这段程序是来判断表单填写的生日是否合法。谢谢!
function checkForm(theForm) {
if ((!theForm.dtBirthYearGet.value) && (!theForm.dtBirthMonthGet.value) && (!theForm.dtBirthDayGet.value)) {
if (!isNaN(theForm.dtBirthYearGet.value) && (!isNaN(theForm.dtBirthMonthGet.value) && (!isNaN(theForm.dtBirthDayGet.value)) {
if (((theForm.dtBirthYearGet.value <= 1900) ¦¦ (theForm.dtBirthMonthGet.value >= 2002)) ¦¦ ((theForm.dtBirthMonthGet.value <=1) ¦¦ (theForm.dtBirthMonthGet.value >= 12)) ¦¦ ((theForm.dtBirthDayGet.value <= 1) ¦¦ (theForm.dtBirthDayGet.value >= 31))) {
window.alert ("您的生日填写有错误.");
theForm.dtBirthYearGet.focus();
return(false);
}
else
window.alert ("您的生日填写有错误.");
theForm.dtBirthYearGet.focus();
return(false);
}
}
}下面有一个这样的表单。
<form ...... name=form onsubmit="return checkForm(form)">
function checkForm(theForm) {
if ((!theForm.dtBirthYearGet.value) && (!theForm.dtBirthMonthGet.value) && (!theForm.dtBirthDayGet.value)) {
if (((theForm.dtBirthYearGet.value <= 1900) ¦¦ (theForm.dtBirthMonthGet.value >= 2002)) ¦¦ ((theForm.dtBirthMonthGet.value <=1) ¦¦ (theForm.dtBirthMonthGet.value >= 12)) ¦¦ ((theForm.dtBirthDayGet.value <= 1) ¦¦ (theForm.dtBirthDayGet.value >= 31))) {
window.alert ("您的生日填写有错误.");
theForm.dtBirthYearGet.focus();
return(false);
}
else {
window.alert ("您的生日填写有错误.");
theForm.dtBirthYearGet.focus();
return(false);
}
}
}对了,你的程序里面好像括号不配对,看看是不是这个地方错?
if(((event.keyCode>=48)&&(event.keyCode<=57))||((event.keyCode>=96)&&(event.keyCode<=105)))
{
alert("该字符为数字!");
}
说明:其中48到57为小键盘0到9十个数字;
96到105为数字0到9十个字符
Vbscript可不可以像javascript写成一个js文件呢?