我编写了一个javascript的函数,但是就是执行不了这个函数,同样差不多的的语句在另外一个jsp里面却可以执行,下面是代码。麻烦各位了!
<SCRIPT LANGUAGE=javascript>
<!--
function checkform(){
if(document.form.ID.value=="")
{
alert("请输入用户名");
}
else if(document.form.PW.value=="")
{
alert("请输入密码");
}
else{
document.form.submit();
}
}
//-->
</SCRIPT>
<!--
.STYLE1 {font-size: 16px}
-->
</head>
<body> <form id="form1" name="form1" method="post" action="dologin.jsp">
登录名
<input type="text" name="ID" />
密码
<input type="password" name="PW" />
<input onclick="javascript:checkform();" type="button" name="Submit" value="提交">
<SCRIPT LANGUAGE=javascript>
<!--
function checkform(){
if(document.form.ID.value=="")
{
alert("请输入用户名");
}
else if(document.form.PW.value=="")
{
alert("请输入密码");
}
else{
document.form.submit();
}
}
//-->
</SCRIPT>
<!--
.STYLE1 {font-size: 16px}
-->
</head>
<body> <form id="form1" name="form1" method="post" action="dologin.jsp">
登录名
<input type="text" name="ID" />
密码
<input type="password" name="PW" />
<input onclick="javascript:checkform();" type="button" name="Submit" value="提交">
<form id="form1" name="form1" method="post" action="dologin.jsp">if(document.form.ID.value=="")
{
alert("请输入用户名");
}
else if(document.form.PW.value=="")
{
alert("请输入密码");
}
else{
document.form.submit();
}
<!--
function checkform(){
if(document.form1.ID.value=="")
{
alert("请输入用户名");
return false;
}
else if(document.form1.PW.value=="")
{
alert("请输入密码");
return false;
}}
//-->
</SCRIPT>
<!--
.STYLE1 {font-size: 16px}
-->
</head>
<body> <form id="form1" name="form1" method="post" action="dologin.jsp" onsubmit="return checkform()">
登录名
<input type="text" name="ID" />
密码
<input type="password" name="PW" />
<input type="submit" name="Submit" value="提交">
if(document.getElementsByName("ID")[0].value=="")
{
alert("请输入用户名");
}
else if(documentgetElementsByName("PW")[0].value=="")
{
alert("请输入密码");
}
else{
document.form.submit();
}
我教你个方法,以后你就知道了。要知道是否调用了这个函数,很简单,
就是多加入几个alert("test"),
看是否执行到了这里啊,
就像我们Java调试一样,用System.out.println();一样。