很简单,可我不会

quary 2003-01-22 02:46:09
怎样在一个表格内根据参数,嵌入另一表格?
比如:
<table width="100%" border="0"><tr><td>这里输出表格</td></tr></table>

n=1时
<table width="100%" border="0"><tr><td>
<table width="90%" border="0"><tr><td>这是表格1</td></tr></table>
</td></tr></table>

n=2时
<table width="100%" border="0"><tr><td>
<table width="80%" border="0"><tr><td>这是表格2</td></tr></table>
</td></tr></table>
...全文
31 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
无爱大叔 2003-01-23
  • 打赏
  • 举报
回复
<INPUT TYPE="text" NAME="txt1"><INPUT TYPE="button" value="change" onclick="changeStyle();">
<script language=javascript>
function changeStyle(){
var n;
n=txt1.value;
if(n==1){
htmlinfo="<table width='100%' border=0'><tr><td>"
htmlinfo+="<table width='90%' border='0'><tr><td>这是表格1</td></tr></table>"
htmlinfo+="</td></tr></table>"
}else if(n==2){
htmlinfo="<table width='100%' border=0'><tr><td>"
htmlinfo+="<table width='80%' border='0'><tr><td>这是表格2</td></tr></table>"
htmlinfo+="</td></tr></table>"
}else{
htmlinfo="<p>请输入1、2";
}
document.all.showtxt.innerHTML=htmlinfo
}
</script>
<table width="100%" border="0"><tr><td>
<table width="100%" border="0"><tr><td>这里输出表格<span id=showtxt></span>
</td></tr></table>
quary 2003-01-23
  • 打赏
  • 举报
回复
up
quary 2003-01-22
  • 打赏
  • 举报
回复
能不能使“<table width="100%" border="0"><tr><td>这里输出表格</td></tr></table>”是静态的htm,嵌入的表格是动态生成的?
烂笔头Danky 2003-01-22
  • 打赏
  • 举报
回复
var tableBox = '<table width="100%" border="0"><tr><td>';
if (n == 1)
tableBox += '<table width="90%" border="0"><tr><td>这是表格1</td></tr></table>';
if (n == 2)
tableBox += '<table width="80%" border="0"><tr><td>这是表格2</td></tr></table>';
tableBox += '</td></tr></table>';
document.write(tableBox);
无爱大叔 2003-01-22
  • 打赏
  • 举报
回复
如果是asp就简单了。
<%if n=1 then%>
...
<%else if n=2 then%>
...
<%end if%>

js的如下:<INPUT TYPE="text" NAME="txt1"><INPUT TYPE="button" value="change" onclick="changeStyle();">
<table width="100%" border="0"><tr><td>
<table width="100%" border="0"><tr><td>这里输出表格
<script language=javascript>
function changeStyle(){
var n;
n=txt1.value;
if(n==1){
document.write("<table width='100%' border=0'><tr><td>");
document.write("<table width='90%' border='0'><tr><td>这是表格1</td></tr></table>");
document.write("</td></tr></table>");
}else if(n==2){
document.write("<table width=100% border=0><tr><td>");
document.write("<table width=80% border=0><tr><td>这是表格2</td></tr></table>");
document.write("</td></tr></table>");
document.write("</td></tr></table>");
}
}
</script>
</td></tr></table>

87,996

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧