1

在下面的 jsp 中,当我更改下拉列表时,值不会被清除。请帮帮我。但是另一个函数(Enable())工作正常。任何人都可以让我知道我哪里出错了。

<%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<title>Untitled Document</title>
<script type="text/javascript">
    document.getElementById("Comp_Text").value=document.getElementById("tgt1").value;
    function Enable(){
        if(document.getElementById("abcd").value=="DAIS")
            {
                    document.getElementById("c1").disabled=true;
                    document.getElementById("c2").disabled=true;
                    document.getElementById("c3").disabled=true;
                    document.getElementById("c4").disabled=true;
                    document.getElementById("c5").disabled=true;
                    document.getElementById("c6").disabled=true;
                    document.getElementById("c1").value='0';
                    document.getElementById("c2").value='0';
                    document.getElementById("c3").value='0';
                    document.getElementById("c4").vaue='0';
                    document.getElementById("c5").value='0';
                    document.getElementById("c6").value='0';
                    document.getElementById("tot1").readOnly=false;
            }
            else
                {
                    document.getElementById("c1").disabled=false;
                    document.getElementById("c2").disabled=false;
                    document.getElementById("c3").disabled=false;
                    document.getElementById("c4").disabled=false;
                    document.getElementById("c5").disabled=false;
                    document.getElementById("c6").disabled=false;
                    document.getElementById("tot1").readOnly=true;
                }

    }
    function Sum()
    {
        var int1=document.getElementById("c1").value;
        var int2=document.getElementById("c2").value;
        var int3=document.getElementById("c3").value;
        var int4=document.getElementById("c4").value;
        var int5=document.getElementById("c5").value;
        var int6=document.getElementById("c6").value;
        document.getElementById("tot1").value=parseInt(int1)+parseInt(int2)+parseInt(int3)+parseInt(int4)+parseInt(int5)+parseInt(int6); 
    }
    function clear(){
                    document.getElementById("c1").value='';
                    document.getElementById("c2").value='';
                    document.getElementById("c3").value='';
                    document.getElementById("c4").vaue='';
                    document.getElementById("c5").value='';
                    document.getElementById("c6").value='';
    }

</script>
</head>

    <body>
<form id="form1" name="form1" method="post" action="UpdateCounts_DB.jsp">
    <input type="text" name="Comp_Text" id="Comp_Text" value="<%=(String)request.getParameter("tgt1")%>" size="100" style="border: 0"/>
    <table width="420" cellspacing="3"> <tr><td width="37">Types</td>
  &nbsp;
  &nbsp;
  &nbsp;
  <td width="127">
      <select name="abcd" id="abcd" onchange="Enable();clear()" >
          <!--<optgroup label="a">-->
          <option value="">Select the Type</option>
          <option value="Updates">Updates</option>  
          <option value="Multibases">Multibases</option>
          <option value="DAIS">DAIS</option>
          <option value="Acds">Admin Codes</option>
          <option value="Legis">Legis</option>
          <option value="LegAll">Legis-All</option>
          <option value="Ins">Ins And Reg</option><!--</optgroup>--></select></td>
          <td width="236"> <font size="-1" color="#0033CC"> Select your Update Type From the Drop Down</font>
          </td> </tr></table>
  <p>
    <label for="DB Count">DB Count</label>&nbsp;&nbsp;&nbsp;&nbsp;
    <input type="text" name="DB_Count" id="DB_Count" style="width:30px" value="<%String abc=(String)request.getAttribute("abc");%>"/>
  </p>
    <font size="5" color="#0033CC">Fill all the below fields, enter Zero if there are no changes in a section</font>
  <table width="312" border="0">
    <tr>
      <td width="156"><label>
      Summary</label></td>
      <td><label for="c1"></label>
          <input type="text" name="c1" id="c1" style="width:30%" onchange="Sum();"/></td>
    </tr>
    <tr>
      <td><label>
    Contents</label></td>
        <td><input type="text" name="c2" id="c2" style="width:30%" onchange="Sum()"/></td>
    </tr>
    <tr>
      <td><label>
    Citation Formats</label></td>
        <td><input type="text" name="c3" id="c3" style="width:30%" onchange="Sum()"/></td>
    </tr>
    <tr>
      <td><label>
      Searching and Fields</label></td>
        <td><input type="text" name="c4" id="c4" style="width:30%"  onchange="Sum()" /></td>
    </tr>
    <tr>
      <td><label>
    Related Research</label></td>
        <td><input type="text" name="c5" id="c5" style="width:30%" onchange="Sum()"/></td>
    </tr>
    <tr>
      <td><label>
    Legal Notices</label></td>
        <td><input type="text" name="c6" id="c6"  style="width:30%" onchange="Sum()"/></td>
    </tr>
    <tr><td>Update Count</td><td>
            <input type="text" name="tot1" id="tot1" style="width:30%" readonly="readonly"/></td></tr>
    </table>
  <p>
    <input type="submit" name="Enter" id="Enter" value="Submit" />
      </p>
</form>
</body>
</html>

谢谢

4

1 回答 1

2

尝试给该clear()函数起一个不同的名称,例如 sayclearValues()clearFields()

function clearFields(){ // name changed

    document.getElementById("c1").value='';
    document.getElementById("c2").value='';
    document.getElementById("c3").value='';
    document.getElementById("c4").vaue='';
    document.getElementById("c5").value='';
    document.getElementById("c6").value='';
}

clear()这可能是由于浏览器使用的事实。clear虽然我在 javascript 关键字中找不到任何参考,但请接受这个

此外,您可能会发现此答案很有帮助,因为它与javascript 中保留字的使用有关,也与保留字有关clear

于 2012-12-10T10:30:40.447 回答