当前位置:首页 > 开发 > Web前端 > JavaScript > 正文

js实现前台动态添加文本框,后台获取文本框内容

发表于: 2013-10-24   作者:171815164   来源:转载   浏览:
摘要: <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://w

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
    <title>
    </title>
    <head>


        <script language="javascript" type="text/javascript">

            var count = 0;
            function additem(id)
            {
                var row, cell, str;
                row = document.getElementById(id).insertRow();
                if (row != null)
                {
                    cell = row.insertCell();
                    cell.innerHTML = "<input id=\"St" + count + "\" type=\"text\" name=\"St" + count + "\" value= \"St" + count + "\"><input type=\"button\" value=\"删除\" onclick=\'deleteitem(this);\'>";
                    count++;
                }
            }
            function deleteitem(obj)
            {
                var curRow = obj.parentNode.parentNode;
                tb.deleteRow(curRow.rowIndex);
            }

            function getsub()
            {
                var re = "";
                for (var i = 0; i < count; i++)
                {
                    re += document.getElementsByName("St" + i)[0].value;

                }
                document.getElementById("Hidden1").value = re;
            }


        </script>
    </head>
    <body >
        <form id="form1" action="request.jsp"><table id="tb"></table>
            <input name="button" type="button" onclick='additem("tb")' value="添加>>"/>
            <input type="submit" name="submit" onclick="getsub()" value="提交"/>
            <input id="Hidden1" name="Hidden1" type="hidden" value="" />
        </form>
    </body>

</html>

js实现前台动态添加文本框,后台获取文本框内容

  • 0

    开心

    开心

  • 0

    板砖

    板砖

  • 0

    感动

    感动

  • 0

    有用

    有用

  • 0

    疑问

    疑问

  • 0

    难过

    难过

  • 0

    无聊

    无聊

  • 0

    震惊

    震惊

版权所有 IT知识库 CopyRight © 2009-2015 IT知识库 IT610.com , All Rights Reserved. 京ICP备09083238号