利用js實(shí)現(xiàn)前臺(tái)動(dòng)態(tài)添加文本框,后臺(tái)獲取文本框內(nèi)容(示例代碼)
一共兩個(gè)頁面,分別如下:
一.創(chuàng)建頁面create.jsp
<%@ 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>
</head>
<body >
<form id="form1" action="request.jsp">
<script language="javascript" type="text/javascript">
var count=0 ;
function additem(id)
{
var row,cell,str;
row = document.getElementByIdx_x(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.getElementByIdx_x("Hidden1").value=re;
}
</script><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>
二.接收數(shù)據(jù)頁面 request.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<html>
<head>
<title>測(cè)試</title>
</head>
<%
String data= request.getParameter("Hidden1");
out.println("取得的數(shù)據(jù)為:"+data);
%>
<body>
</body>
</html>
相關(guān)文章
APP中javascript+css3實(shí)現(xiàn)下拉刷新效果
本文給大家分享的是如何在APP中使用javascript結(jié)合CSS3實(shí)現(xiàn)下拉刷新特效的代碼,非常的簡(jiǎn)單實(shí)用,有需要的小伙伴可以參考下。2016-01-01處理JavaScript浮點(diǎn)數(shù)精度問題的解決方案
在開發(fā)過程中,特別是涉及到金額計(jì)算或需要精確比較的場(chǎng)景,浮點(diǎn)數(shù)精度問題是一個(gè)常見而重要的挑戰(zhàn),本文將介紹在JavaScript中如何識(shí)別、理解和解決這些問題,并提供一些實(shí)用的技巧和建議,需要的朋友可以參考下2024-06-06基于JS實(shí)現(xiàn)的隨機(jī)數(shù)字抽簽實(shí)例
本文分享了基于JS實(shí)現(xiàn)的隨機(jī)數(shù)字抽簽的實(shí)例代碼。小編認(rèn)為具很好的參考價(jià)值,感興趣的朋友可以看下2016-12-12JS實(shí)現(xiàn)獲取當(dāng)前所在周的周六、周日示例分析
這篇文章主要介紹了JS實(shí)現(xiàn)獲取當(dāng)前所在周的周六、周日,結(jié)合具體實(shí)例形式分析了javascript針對(duì)日期時(shí)間的獲取與計(jì)算相關(guān)操作技巧,需要的朋友可以參考下2019-05-05js浮點(diǎn)數(shù)保留兩位小數(shù)點(diǎn)示例代碼(四舍五入)
本篇文章主要介紹了js浮點(diǎn)數(shù)保留兩位小數(shù)點(diǎn)示例代碼(四舍五入) 需要的朋友可以過來參考下,希望對(duì)大家有所幫助2013-12-12