2个回答
展开全部
用JS生成:
<%@ page language="java" pageEncoding="UTF-8"%>
<html>
<head>
<title>Test</title>
<script type="text/javascript">
function toTable(){
var rows = document.getElementById("txtRow").value;
var cols = document.getElementById("txtCol").value;
var textHTML = '<table cellpadding="0" cellspacing="0" border="1" width="100%">';
for(var i=0; i<rows; i++){
textHTML += '<tr align="center" height="30">';
for(var j=0; j<cols; j++){
textHTML += "<td>[" + (i+1) + "] | [" + (j+1) + "]</td>";
}
}
textHTML += "</table>";
document.getElementById("testTable").innerHTML = textHTML;
}
</script>
</head>
<body onload="toTable();">
行:<input type="text" name="txtRow" value="3" style="width: 50px;"/>
列:<input type="text" name="txtCol" value="3" style="width: 50px;"/>
<input type="button" name="btnGo" value="生成" onclick="toTable();"/>
<br />
<div id="testTable">
</div>
</body>
</html>
----------------------------------------------------------
用JAVA代码:
<%@ page language="java" pageEncoding="UTF-8"%>
<html>
<head>
<title>Test</title>
</head>
<body>
<div>
<table cellpadding="0" cellspacing="0" border="1" width="100%">
<%
int rows = 3; // 多少行
int cols = 3; // 多少列
for(int i = 0; i < rows; i++ ){
%>
<tr align="center" height="30">
<%
for(int j = 0; j < cols; j++ ){
%>
<td>[<%=i+1 %>] | [<%=j+1 %>]</td>
<%
}
}
%>
</table>
</div>
</body>
</html>
<%@ page language="java" pageEncoding="UTF-8"%>
<html>
<head>
<title>Test</title>
<script type="text/javascript">
function toTable(){
var rows = document.getElementById("txtRow").value;
var cols = document.getElementById("txtCol").value;
var textHTML = '<table cellpadding="0" cellspacing="0" border="1" width="100%">';
for(var i=0; i<rows; i++){
textHTML += '<tr align="center" height="30">';
for(var j=0; j<cols; j++){
textHTML += "<td>[" + (i+1) + "] | [" + (j+1) + "]</td>";
}
}
textHTML += "</table>";
document.getElementById("testTable").innerHTML = textHTML;
}
</script>
</head>
<body onload="toTable();">
行:<input type="text" name="txtRow" value="3" style="width: 50px;"/>
列:<input type="text" name="txtCol" value="3" style="width: 50px;"/>
<input type="button" name="btnGo" value="生成" onclick="toTable();"/>
<br />
<div id="testTable">
</div>
</body>
</html>
----------------------------------------------------------
用JAVA代码:
<%@ page language="java" pageEncoding="UTF-8"%>
<html>
<head>
<title>Test</title>
</head>
<body>
<div>
<table cellpadding="0" cellspacing="0" border="1" width="100%">
<%
int rows = 3; // 多少行
int cols = 3; // 多少列
for(int i = 0; i < rows; i++ ){
%>
<tr align="center" height="30">
<%
for(int j = 0; j < cols; j++ ){
%>
<td>[<%=i+1 %>] | [<%=j+1 %>]</td>
<%
}
}
%>
</table>
</div>
</body>
</html>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询