错误:无法获取属性value的值,对象为null或未定义,怎么解决啊? 20

运行时说21和34行有错,怎么改啊<!doctypehtml><htmllang="en"><head><metacharset="UTF-8"><metaname="G... 运行时说21和34行有错,怎么改啊
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="Generator" content="EditPlus®">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<title>Document</title>
<style type="text/css">

</style>
<script type="text/javascript">
<!--

function $(id){
return document.getElementById("id");
}
function checkName()
{
var myna=$("mytext").value;
var mynalen=myna.length;
var firstchar=myna.charAt(0);
if(mynalen<5 || mynalen>20)
{
alert("用户名长度不规范化!");
$("err_name").innerHTML="用户名长度不规范化!";
}else if (firstchar>="0"&& firstchar<="9")
{
$("err_name").innerHTML="用户名首字符有不规范化!";
}
}
function checkPsd1(){
var mina=$("mypsd1").value;
var mimalen=mima.length;
if (mimalen<5||miam>20)
{
$("err_psd1").innerHTML="密码长度不规范";
}else if (mims.length==""||mima==null)
{
$("err_psd1").innerHTML="密码不能为空";
}
}

function cheakPsd2(){

}
function cheakPsd1(){

}

//-->
</script>
</head>
<body>
<div id="" class="">
<form method="post" action="">
<table border="1px" color="bule" width="600px" height="220px">
<caption>表单验证</caption>
<tr>

<td>用户名</td>
<td><input type="text" name="" id="mytext" onblur="checkName();"></td>
<td><label id="err_name"></label></td>
</tr>
<tr>

<td>密码</td>
<td><input type="password" name="" id="mypsd1" onblur="checkPsd1();"></td>
<td><label id="err_psd1"></label></td>
</tr>
<tr>

<td>确认密码 </td>
<td><input type="password" name="" id="mypsd2" onblur="checkPsd2();"></td>
<td><label id="err_psd2"></label></td>
</tr>
<tr>

<td>电子邮件</td>
<td><input type="text" name="" id="myemail" onblur="checkEmail();"></td>
<td><label id="err_email"></label></td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="button" value="提交" onclick="">
<input type="reset">
</td>
</tr>
</table>
</form>
</div>
</body>
</html>
展开
 我来答
金芃阁
高粉答主

2018-03-30 · 每个回答都超有意思的
知道大有可为答主
回答量:216
采纳率:100%
帮助的人:96.8万
展开全部

获取为空,利用debug调试,找到第一次值传递为空的地方,重新查看那个地方使用的方法即可。

具体操作:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<title>Insert title here</title>

</head>

<script type="text/javascript">

function baocun() {

//id

var addnumber1 = document.getElementsByName("myid");

alert(addnumber1[0].value);

var addnumber2 = document.getElementById("myid").value;

//名字

var addname1 = document.getElementsByName("myname");

alert(addname1[0].value);

var addname2 = document.getElementById("myname").value;

//学校

var addschool1 = document.getElementsByName("myschool");

var addschool2 = document.getElementById("myschool").value;

//邮箱

var addemail1 = document.getElementsByName("myemail");

var addemail2 = document.getElementById("myemail").value;

if (addnumber2 == null || addnumber2 == "") {

alert("学号不能空!");

} else if (addname2 == null || addname2 == "") {

alert("姓名不能空!");

} else if (addschool2 == null || addschool2 == "") {

alert("学校不能空!");

} else {

document.getElementById("id").value = addnumber1[0].value;

document.getElementById("nameid").value = addname1[0].value;

document.getElementById("schoolid").value = addschool1[0].value;

document.getElementById("emailid").value = addemail1[0].value;

tijiao.submit();

location.href = "Info.jsp";

}

}

function no() {

location.href = "Info.jsp";

}

</script>

<body>

<center>

<h2>----页面表单提交小程序----</h2>

<table width="600">

<tr>

<td>

<h4>添加页面</h4>

</td>

</tr>

</table>

<form action="AddServelet" method="post" name="tijiao">

<input type="hidden" name="addid" value="" id="id"> <input

type="hidden" name="addname" value="" id="nameid"> <input

type="hidden" name="addschool" value="" id="schoolid"> <input

type="hidden" name="addemail" value="" id="emailid">

</form>

<table border="1" width="600">

<tr>

<th width="300"> 学 号 </th>

<th width="300"> 姓 名 </th>

<th width="1000"> 学 校 </th>

<th width="1000"> 邮 箱 </th>

</tr>

<tr>

<td><input type="text" id="myid" name="myid"

onKeypress="return (/[\d.]/.test(String.fromCharCode(event.keyCode)))"

style="ime-mode: Disabled" title="只能输入数字" />

</td>

<td><input type="text" name="myname" id="myname" />

</td>

<td><input type="text" name="myschool" id="myschool" />

</td>

<td><input type="text" name="myemail" id="myemail" />

</td>

</tr>

</table>

<p />

<button type="button" onclick="baocun();"> 保 存 </button>

<button type="button" onclick="no();"> 取 消 </button>

</center>

<!-- 添加功能 -->

</body>

</html>

山水阿锐
2015-05-31 · TA获得超过34.3万个赞
知道顶级答主
回答量:23.7万
采纳率:91%
帮助的人:3.2亿
展开全部
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
</head>
<script type="text/javascript">
function baocun() {
//id
var addnumber1 = document.getElementsByName("myid");
alert(addnumber1[0].value);
var addnumber2 = document.getElementById("myid").value;
//名字
var addname1 = document.getElementsByName("myname");
alert(addname1[0].value);
var addname2 = document.getElementById("myname").value;
//学校
var addschool1 = document.getElementsByName("myschool");
var addschool2 = document.getElementById("myschool").value;
//邮箱
var addemail1 = document.getElementsByName("myemail");
var addemail2 = document.getElementById("myemail").value;
if (addnumber2 == null || addnumber2 == "") {
alert("学号不能空!");
} else if (addname2 == null || addname2 == "") {
alert("姓名不能空!");
} else if (addschool2 == null || addschool2 == "") {
alert("学校不能空!");
} else {
document.getElementById("id").value = addnumber1[0].value;
document.getElementById("nameid").value = addname1[0].value;
document.getElementById("schoolid").value = addschool1[0].value;
document.getElementById("emailid").value = addemail1[0].value;
tijiao.submit();
location.href = "Info.jsp";
}

}
function no() {
location.href = "Info.jsp";
}
</script>
<body>
<center>
<h2>----页面表单提交小程序----</h2>
<table width="600">
<tr>
<td>
<h4>添加页面</h4>
</td>
</tr>
</table>
<form action="AddServelet" method="post" name="tijiao">
<input type="hidden" name="addid" value="" id="id"> <input
type="hidden" name="addname" value="" id="nameid"> <input
type="hidden" name="addschool" value="" id="schoolid"> <input
type="hidden" name="addemail" value="" id="emailid">
</form>
<table border="1" width="600">
<tr>
<th width="300"> 学 号 </th>
<th width="300"> 姓 名 </th>
<th width="1000"> 学 校 </th>
<th width="1000"> 邮 箱 </th>
</tr>
<tr>
<td><input type="text" id="myid" name="myid"
onKeypress="return (/[\d.]/.test(String.fromCharCode(event.keyCode)))"
style="ime-mode: Disabled" title="只能输入数字" />
</td>
<td><input type="text" name="myname" id="myname" />
</td>
<td><input type="text" name="myschool" id="myschool" />
</td>
<td><input type="text" name="myemail" id="myemail" />
</td>
</tr>
</table>
<p />
<button type="button" onclick="baocun();"> 保 存 </button>

<button type="button" onclick="no();"> 取 消 </button>

</center>
<!-- 添加功能 -->
</body>
</html>
本回答被网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式