html总是提示缺少对象

html总是提示缺少对象,第1张

调试了一下,发现几个问题:

1.

<input type="text" name="e-mail">

这句中name不能出现“-”否则javascript中会认为是运算符,改一下:

<input type="text" name="email">

2.javascript中少了个“}”,改成这样:

<script language="javascript">

function check(){

var name=form1.name.value

var pwd=form1.pwd.value

var rpwd=form1.rpwd.value

var e_mail=form1.email.value

if (name.length >5) {

alert("昵称的长度应小于5个字符")

} else if (name.length <2) {

alert("昵称的长度应大于2")

} else if (pwd.length >20) {

alert("密码长度太长,请重新输入")

} else if (rpwd.length <6) {

alert("密码太短,账号不安全,请重新输入")

} else if (pwd != rpwd) {

alert("两次密码输入不同重新输入")

}

else {

form1.submit()

}

}

</script>

你这里面有很多错误 我给你改完了 看看吧

<html>

<head>

<script>

function checkusername() {

var username = document.getElementById('username')

var usernamemsg = document.getElementById('usernamemsg')

usernamemsg.innerHTML = ''

if (username.value.length == 0) {

usernamemsg.innerHTML = '用户名不允许为空'

}

}

function checkpassword() {

var password = document.getElementById('password')

var passwordmsg = document.getElementById('passwordmsg')

passwordmsg.innerHTML = ''

if (password.value.length == 0) {

passwordmsg.innerHTML = '密码不允许为空'

} else if (password.value.length>=6&&password.value.length<=8) {

passwordmsg.innerHTML = ''

}else{

passwordmsg.innerHTML = '密码长度须在6~8位之间'

}

}

function checkrepasswords() {

var userpassword = document.f1.password.value

var userpassword2 = document.f1.repassword.value

var repasswordmsgz = document.getElementById('repasswordmsg')

repasswordmsgz.innerHTML=""

if (userpassword2==userpassword ) {

repasswordmsgz.innerHTML=""

}else{

repasswordmsgz.innerHTML="密码不一致"

}

}

</script>

</head>

<body>

<form action="#" name="f1">

<table border="0" align="center">

<tr>

<td>

用户名:

</td>

<td>

<input type="text" name="username" id="username"

onblur="checkusername()">

<span id="usernamemsg" style="color: red"></span>

</td>

</tr>

<tr>

<td>

密码:

</td>

<td>

<input type="text" name="password" id="password"

onblur="checkpassword()">

<span id="passwordmsg" style="color: red"></span>

</td>

</tr>

<tr>

<td>

重复密码:

</td>

<td>

<input type="text" name="repassword" id="repassword" onBlur="checkrepasswords()">

<span id="repasswordmsg" style="color: red"></span>

</td>

</tr>

<tr>

<td>

性别:

</td>

<td>

<input type="radio" name="gender">

<input type="radio" name="gender">

</td>

</tr>

<tr>

<td>

个人简介:

</td>

<td>

<textarea rows="5" cols="15" name="introduce">

</textarea>

</td>

</tr>

<tr>

<td>

籍贯:

</td>

<td>

<select name="jiguan">

<option value="1">

北京

</option>

<option value="2">

上海

</option>

<option value="3">

广州

</option>

</select>

</td>

</tr>

<tr>

<td>

<input type="submit" value="提交注册">

<input type="button" value="登录">

</td>

<td>

<center>

<input type="reset" value="重新注册">

</center>

</td>

</tr>

</table>

</form>

</body>

</html>

顺便说一句 只有用var userpassword = document.f1.password.value方法才能获取到密码的值


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/7150376.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-02
下一篇 2023-04-02

发表评论

登录后才能评论

评论列表(0条)

保存