
ASP中,onsubmit该如何使用?为什么我设置后,form表单中要执行的onsubmit没效果呢?
<scripttype="text/javascript"language="JavaScript">functionchk(theForm){if(theForm.na...
<script type ="text/javascript" language="JavaScript"> function chk(theForm) {
if (theForm.name.value == "") {
alert("请载入相关文件!");
theForm.name.focus();
return (false);
}
return true
}
</script>
<html><head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body text="#000000">
<table width="98%" border="0" cell
<form name="form1" method="post" action="?action=go" onsubmit="return chk(this)">padding="0" cellspacing="0" align="center" class=TableBorder>
<input id="File1" type="file" />
<input id="Button1" type="Button" value="批量导入" />
</table>
</form>
</body>
</html> 展开
if (theForm.name.value == "") {
alert("请载入相关文件!");
theForm.name.focus();
return (false);
}
return true
}
</script>
<html><head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body text="#000000">
<table width="98%" border="0" cell
<form name="form1" method="post" action="?action=go" onsubmit="return chk(this)">padding="0" cellspacing="0" align="center" class=TableBorder>
<input id="File1" type="file" />
<input id="Button1" type="Button" value="批量导入" />
</table>
</form>
</body>
</html> 展开
3个回答
展开全部
1. 选择档案的字段id是File1,不是name
2. 必须要有Submit的按钮,否则onSubmit不会作用
所以改成这样就可以运作了:
<script type ="text/javascript" language="JavaScript">
function chk(theForm) {
if (theForm.File1.value == "") {
alert("请载入相关文件!");
theForm.File1.focus();
return (false);
}
return true
}
</script>
<html><head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body text="#000000">
<table width="98%" border="0" cellpadding="0" cellspacing="0" align="center" class=TableBorder>
<form name="form1" method="post" action="?action=go" onsubmit="return chk(this)">
<input id="File1" type="file" />
<input id="Button1" type="submit" value="批量导入" />
</table>
</form>
</body>
</html>
2. 必须要有Submit的按钮,否则onSubmit不会作用
所以改成这样就可以运作了:
<script type ="text/javascript" language="JavaScript">
function chk(theForm) {
if (theForm.File1.value == "") {
alert("请载入相关文件!");
theForm.File1.focus();
return (false);
}
return true
}
</script>
<html><head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body text="#000000">
<table width="98%" border="0" cellpadding="0" cellspacing="0" align="center" class=TableBorder>
<form name="form1" method="post" action="?action=go" onsubmit="return chk(this)">
<input id="File1" type="file" />
<input id="Button1" type="submit" value="批量导入" />
</table>
</form>
</body>
</html>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
return false不能加括号。另外脚本中,focus的对象应该是file1
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
<script type ="text/javascript" language="JavaScript"> function chk(theForm) {
if (theForm.File1.value == "") {
alert("请载入相关文件!");
theForm.File1.focus();
return false;
}
return true;
}
</script>
还有
<input id="File1" name="File1" type="file" />
if (theForm.File1.value == "") {
alert("请载入相关文件!");
theForm.File1.focus();
return false;
}
return true;
}
</script>
还有
<input id="File1" name="File1" type="file" />
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询