0

下面是我用来getElementById的java脚本。但这是行不通的。

<script type="text/javascript">

   function invoke(but)
        {
            if(but==5)
            {
                alert(document.firstChild);

            }
            else if(but==6)
            {
                window.location.href="index1.jsp";
            }

        }
       function UnBloc1()
        {
            document.getElementById("temp2").style.display="block";
            document.getElementById("temp4").style.display="block";
        }
    </script>

适用的jsp如下

<%
try{
int i=0;
int temp=0, temp1=0,temp2=0, temp3=0, temp4=0;
for(i=0;i<14;i++)

    {
       temp=temp+1;
       temp1=temp1+1;
       temp2=temp2+1;
       temp3=temp3+1;
       temp4=temp4+1;        
       i++;
       %>

                  <tr><form name="abc" method="post" action="">
                  <td><input type="text" value="<%=i%>" name="id1" id="id1"></td>
                  <td><center><input type="text" value="a" readonly="readonly" id="abc<%=i%>" name="abc<%=i%>" size="100"></center></td>
                  <td><input type="Submit" value="Resume" name="temp1<%=i%>" id="temp1<%=i%>" onClick="invoke(5)"></td>
                  <td><input type="button" value="Update Answer" onClick="UnBloc1()"></td>
                  <td><input type="text" name="temp3<%=i%>" id="temp3<%=i%>" style="border:hidden; display: none"/></td>           
                  <td><input type="Submit" value="Submit Answer" name="temp4<%=i%>" id="temp4<%=i%>" style="display: none" onClick="invoke(6)"/>

                  </td>
                  </form></tr>

    <% }

}
catch(Exception e)
           {

out.println(e);

}
%>  

生成的源代码如下。在这里,我想知道如何在 getElmentById 中为 javascript 中的 UnBloc() 方法的按钮获取动态按钮值。

<html>
<head><script type="text/javascript">

   function invoke(but)
        {
            if(but==5)
            {
                alert("hi");

            }
            else if(but==6)
            {
                window.location.href="index1.jsp";
            }

        }
       function UnBloc1()
        {
            document.getElementById("temp2").style.display="block";
            document.getElementById("temp4").style.display="block";
        }
    </script> </head>

                  <tr><form name="abc" method="post" action="">
                  <td><input type="text" value="1" name="id1" id="id1"></td>
                  <td><center><input type="text" value="a" readonly="readonly" id="abc1" name="abc1" size="100"></center></td>
                  <td><input type="Submit" value="Resume" name="temp11" id="temp11" onClick="invoke(5)"></td>
                  <td><input type="button" value="Update Answer" onClick="UnBloc1()"></td>
                  <td><input type="text" name="temp31" id="temp31" style="border:hidden; display: none"/></td>           
                  <td><input type="Submit" value="Submit Answer" name="temp41" id="temp41" style="display: none" onClick="invoke(6)"/>

                  </td>
                  </form></tr>



                  <tr><form name="abc" method="post" action="">
                  <td><input type="text" value="3" name="id1" id="id1"></td>
                  <td><center><input type="text" value="a" readonly="readonly" id="abc3" name="abc3" size="100"></center></td>
                  <td><input type="Submit" value="Resume" name="temp13" id="temp13" onClick="invoke(5)"></td>
                  <td><input type="button" value="Update Answer" onClick="UnBloc1()"></td>
                  <td><input type="text" name="temp33" id="temp33" style="border:hidden; display: none"/></td>           
                  <td><input type="Submit" value="Submit Answer" name="temp43" id="temp43" style="display: none" onClick="invoke(6)"/>

                  </td>
                  </form></tr>



                  <tr><form name="abc" method="post" action="">
                  <td><input type="text" value="5" name="id1" id="id1"></td>
                  <td><center><input type="text" value="a" readonly="readonly" id="abc5" name="abc5" size="100"></center></td>
                  <td><input type="Submit" value="Resume" name="temp15" id="temp15" onClick="invoke(5)"></td>
                  <td><input type="button" value="Update Answer" onClick="UnBloc1()"></td>
                  <td><input type="text" name="temp35" id="temp35" style="border:hidden; display: none"/></td>           
                  <td><input type="Submit" value="Submit Answer" name="temp45" id="temp45" style="display: none" onClick="invoke(6)"/>

                  </td>
                  </form></tr>



                  <tr><form name="abc" method="post" action="">
                  <td><input type="text" value="7" name="id1" id="id1"></td>
                  <td><center><input type="text" value="a" readonly="readonly" id="abc7" name="abc7" size="100"></center></td>
                  <td><input type="Submit" value="Resume" name="temp17" id="temp17" onClick="invoke(5)"></td>
                  <td><input type="button" value="Update Answer" onClick="UnBloc1()"></td>
                  <td><input type="text" name="temp37" id="temp37" style="border:hidden; display: none"/></td>           
                  <td><input type="Submit" value="Submit Answer" name="temp47" id="temp47" style="display: none" onClick="invoke(6)"/>

                  </td>
                  </form></tr>



                  <tr><form name="abc" method="post" action="">
                  <td><input type="text" value="9" name="id1" id="id1"></td>
                  <td><center><input type="text" value="a" readonly="readonly" id="abc9" name="abc9" size="100"></center></td>
                  <td><input type="Submit" value="Resume" name="temp19" id="temp19" onClick="invoke(5)"></td>
                  <td><input type="button" value="Update Answer" onClick="UnBloc1()"></td>
                  <td><input type="text" name="temp39" id="temp39" style="border:hidden; display: none"/></td>           
                  <td><input type="Submit" value="Submit Answer" name="temp49" id="temp49" style="display: none" onClick="invoke(6)"/>

                  </td>
                  </form></tr>



                  <tr><form name="abc" method="post" action="">
                  <td><input type="text" value="11" name="id1" id="id1"></td>
                  <td><center><input type="text" value="a" readonly="readonly" id="abc11" name="abc11" size="100"></center></td>
                  <td><input type="Submit" value="Resume" name="temp111" id="temp111" onClick="invoke(5)"></td>
                  <td><input type="button" value="Update Answer" onClick="UnBloc1()"></td>
                  <td><input type="text" name="temp311" id="temp311" style="border:hidden; display: none"/></td>           
                  <td><input type="Submit" value="Submit Answer" name="temp411" id="temp411" style="display: none" onClick="invoke(6)"/>

                  </td>
                  </form></tr>



                  <tr><form name="abc" method="post" action="">
                  <td><input type="text" value="13" name="id1" id="id1"></td>
                  <td><center><input type="text" value="a" readonly="readonly" id="abc13" name="abc13" size="100"></center></td>
                  <td><input type="Submit" value="Resume" name="temp113" id="temp113" onClick="invoke(5)"></td>
                  <td><input type="button" value="Update Answer" onClick="UnBloc1()"></td>
                  <td><input type="text" name="temp313" id="temp313" style="border:hidden; display: none"/></td>           
                  <td><input type="Submit" value="Submit Answer" name="temp413" id="temp413" style="display: none" onClick="invoke(6)"/>

                  </td>
                  </form></tr>


    </table></body></html>

谢谢

4

0 回答 0