为什么始终执行不到? =。=!下面两个不对、还是没执行到JS、直接跳转过去了?

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<script type="text/javascript" language="javascript">
function name(){
if(document.form.name.value==''){
window.alert("再见啦!");
}
}

</script>

<html>
<head>
<title>LOGIN</title>
</head>
<body>
<form action="Chenking.jsp" method="post">
<h1>注册页面</h1>
姓    名:<input type="text" name="name" size="20" onchange="javascript:name()"/><br>
密    码:<input type="password" name="password" size="20" /><br>
确认密码:<input type="password" name="password1" size="20" /><br>
性    别:<input type="radio" name="sex" value="boy" checked="checked"/ >男
<input type="radio" name="sex" value="gril"/>女<br>
邮    箱:<input type="text" name="mali"/><br>
<br>
     <input type="submit" value="提交"/>    <input type="submit" value="重置"/></br>

</form>

</body>
</html>

============

慕姐4208626
浏览 138回答 3
3回答

慕码人2483693

<a class="cur STRING_BASE" href="javascript:toHome()"><strong>基本信息</strong></a>这样就可以了,toHome()为js定义的函数

翻阅古今

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%><SCRIPT type="text/javascript" language="javascript">function checkName(){if(document.getElementById("name").value==''){window.alert("姓名不能为空!");return false;}else if(document.getElementById("password").value==''){window.alert("密码不能为空!");return false;}else if(document.getElementById("password1").value==''){window.alert("确认密码不能为空!");return false;}else if(!(document.getElementById("password1").value==document.getElementById("password").value)){window.alert("确认密码与密码不一致!");return false;}else if(document.getElementById("mali").value==''){window.alert("邮箱不能为空!");return false;}}</SCRIPT><HTML><HEAD><TITLE>LOGIN</TITLE></HEAD><BODY><FORM action="Chenking.jsp" method="post" name="form" onsubmit="return checkName();"><H1>注册页面</H1>姓 名:<INPUT type="text" id="name" size="20" /><BR>密 码:<INPUT type="password" id="password" size="20" /><BR>确认密码:<INPUT type="password" id="password1" size="20" /><BR>性 别:<INPUT type="radio" name="sex" value="boy" checked="checked"/ >男 <INPUT type="radio" name="sex" value="gril"/>女<BR>邮 箱:<INPUT type="text" id="mali"/><BR><BR><INPUT name="提交" type="submit" value="提交" /><INPUT name="重置" type="reset" value="重置"/></br></FORM></BODY></HTML>我把你所有的验证全部放到表单提交的时候去验证的!&nbsp;

千巷猫影

这样就行了:<form name="form" action="Chenking.jsp" method="post"><input type="submit" value="提交" onchange="name();"/>美女,测试了下你的代码,js好像有问题。或者按我这样写也可以:<html><head><title>LOGIN</title></head><body><form name="form" action="Chenking.jsp" method="post"><h1>注册页面</h1>姓 名:<input type="text" name="name" size="20" id="name"/><br>密 码:<input type="password" name="password" size="20" /><br>确认密码:<input type="password" name="password1" size="20" /><br>性 别:<input type="radio" name="sex" value="boy" checked="checked"/ >男<input type="radio" name="sex" value="gril"/>女<br>邮 箱:<input type="text" name="mali"/><br><br><input type="submit" value="提交" onClick="return check();"/> <input type="submit" value="重置"/></br></form><script LANGUAGE="javascript"><!--function checkspace(checkstr) {var str = '';for(i = 0; i < checkstr.length; i++) {str = str + ' ';}return (str == checkstr);}function check(){if(checkspace(document.form.name.value)) {document.form.name.focus();alert("再见了,美女!");return false;}}//--></script></body></html>
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java
Html5