啥原因呢 怎么改啊

解决方案 »

  1.   

    看不到图  上代码是不是没拿到相应的对象看看元素上面ID 跟document.getElementById里面写的ID对应吗
      

  2.   

    还有 元素是input标签吗?
      

  3.   

    <%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
    <!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">&nbsp;学&nbsp;号&nbsp;</th>
    <th width="300">&nbsp;姓&nbsp;名&nbsp;</th>
    <th width="1000">&nbsp;学&nbsp;校&nbsp;</th>
    <th width="1000">&nbsp;邮&nbsp;箱&nbsp;</th>
    </tr>
    <tr>
    <td><input type="text" name="myid"
    onKeypress="return (/[\d.]/.test(String.fromCharCode(event.keyCode)))"
    style="ime-mode: Disabled" title="只能输入数字">
    </td>
    <td><input type="text" name="myname">
    </td>
    <td><input type="text" name="myschool">
    </td>
    <td><input type="text" name="myemail">
    </td>
    </tr>
    </table>
    <p />
    <button type="button" onclick="baocun();">&nbsp;保&nbsp;存&nbsp;</button>
    &nbsp;&nbsp;&nbsp;
    <button type="button" onclick="no();">&nbsp;取&nbsp;消&nbsp;</button>
    &nbsp;&nbsp;&nbsp; </center>
    <!-- 添加功能 -->
    </body>
    </html>
      

  4.   

    <!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">&nbsp;学&nbsp;号&nbsp;</th>
    <th width="300">&nbsp;姓&nbsp;名&nbsp;</th>
    <th width="1000">&nbsp;学&nbsp;校&nbsp;</th>
    <th width="1000">&nbsp;邮&nbsp;箱&nbsp;</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();">&nbsp;保&nbsp;存&nbsp;</button>
    &nbsp;&nbsp;&nbsp;
    <button type="button" onclick="no();">&nbsp;取&nbsp;消&nbsp;</button>
    &nbsp;&nbsp;&nbsp;</center>
    <!-- 添加功能 -->
    </body>
    </html>
      

  5.   

    <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";
    }
      

  6.   

    <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" />
    input标签得加上ID你js用的是getElementById是根据ID拿到相应标签对象的
      

  7.   

    添加相关标签的id,id的属性值,且与函数中getElementById的值一样。