在jsp页面上有一个按钮,点击一下添加一个<s:file>控件,如何实现?

解决方案 »

  1.   

    Jquery:<body>
    <input type="button" id="btn"/><script>
    $(document).ready(function() {
    $("#btn").click(function() {
    var str = "<s:file ............. />"
    $(this).after(str);
    });
    });
    </script>
    </body>
    简单示意。。
    至于JS。好久不用了。。忘记怎么写了JQUERY王道
      

  2.   


    <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
    <%@ taglib  prefix="s" uri="/struts-tags"%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <head>
       
        <title>My JSP 'upload.jsp' starting page</title>
       
     <meta http-equiv="pragma" content="no-cache">
     <meta http-equiv="cache-control" content="no-cache">
     <meta http-equiv="expires" content="0">   
     <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
     <meta http-equiv="description" content="This is my page">
     <!--
     <link rel="stylesheet" type="text/css" href="styles.css">
     -->
    <script type="text/javascript">
    function addmore(){
    var td=document.getElementById("more");
    var br=document.createElement("br");
    var file=document.createElement("input");
    var button=document.createElement("input");
     file.type="file";
     file.name="file";
     button.type="button";
     button.value="remove";
     button.onclick=function(){
     td.removeChild(br);
      td.removeChild(file);
       td.removeChild(button);
     }
     
     td.appendChild(br);
     td.appendChild(file);
     td.appendChild(button);
    }
    </script>
      </head>
     
      <body>
        <s:form action="upload" theme="simple" enctype="multipart/form-data" method="post">
        <table>
        <tr>
         <td>name</td>
         <td><s:textfield name="name" ></s:textfield></td>
        </tr>
        <tr>
         <td>pass</td>
         <td><s:textfield name="pass" ></s:textfield></td>
        </tr>
        <tr>
         <td>file</td>
         <td id="more"><s:file name="file" /><input type="button" value="more" onclick="addmore();"/></td>
        </tr>
        <tr>
         <td>submit</td>
         <td><s:submit name="submit"></s:submit></td>
        </tr>
        </table>
       </s:form>
      </body>
    </html>