下面用js实现可以生成用户所需行数的表格。
1.首先在body中填入下列代码,获取用户填入的行数值
效果如下图所示:
2.header中添加js代码
<script> <BR>function table() { <BR>if (document.getElementById("Num").value == "" || document.getElementById("Num").value.search("^[0-9]*$") == -1) { <BR>document.getElementById("errmsg1").style.display = "block";//判断Num是否为空或不是数字 提示错误 <BR>document.getElementById("errmsg1").innerHTML = "提示信息:行数为空或不是数字!"; <BR>} <BR>else { <BR>document.getElementById("errmsg1").style.display = "none";//隐藏提示信息 <BR>var Num = parseInt(document.getElementById("Num").value); //获取行数 <BR>var flag = true; <BR>var data = ""; <BR>data += " <table >"; <BR>data += " <tr>" + <BR>"<td >we are" + <BR>"<td >zhuzhu" + <BR>"<td >dudu" + <BR>"" ; <BR>for (var i = 1; i <= Num; i++) { <BR>data += "<tr >"; <BR>data += "<td>" + i + ""; <BR>data += "<td><input name='ColdDay"+i+"' type='text' class='input'>"; <BR>data += "<td><input name='ColdCureMethod"+i+"' type='text' class='input'>"; <BR>data += ""; <BR>} <BR>data += ""; <BR>document.getElementById("div1").style.display = "block"; <BR>document.getElementById("table1").innerHTML = data; <BR>} <BR>} <BR></script>
生成效果如下:
3.所有代码如下
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
test <script> <BR>function table() { <BR>if (document.getElementById("Num").value == "" || document.getElementById("Num").value.search("^[0-9]*$") == -1) { <BR>document.getElementById("errmsg1").style.display = "block";//判断payNum是否为空或不是数字 提示错误 <BR>document.getElementById("errmsg1").innerHTML = "提示信息:行数为空或不是数字!"; <BR>} <BR>else { <BR>document.getElementById("errmsg1").style.display = "none";//隐藏提示信息 <BR>var Num = parseInt(document.getElementById("Num").value); //获取分期数 <BR>var flag = true; <BR>var data = ""; <BR>data += " <table >"; <BR>data += " <tr>" + <BR>"<td >we are" + <BR>"<td >zhuzhu" + <BR>"<td >dudu" + <BR>"" ; <BR>for (var i = 1; i <= Num; i++) { <BR>data += "<tr >"; <BR>data += "<td>" + i + ""; <BR>data += "<td><input name='ColdDay"+i+"' type='text' class='input'>"; <BR>data += "<td><input name='ColdCureMethod"+i+"' type='text' class='input'>"; <BR>data += ""; <BR>} <BR>data += ""; <BR>document.getElementById("div1").style.display = "block"; <BR>document.getElementById("table1").innerHTML = data; <BR>} <BR>} <BR></script>