内容来动态生成表格:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
</table>-->
<script type="text/javascript">
var bgColor = prompt('请输入表格背景颜色');
var border = prompt('请输入表格边框宽度');
var width = prompt('请输入表格宽度');
var align = prompt('请输入表格对齐方式');
var height = prompt('请输入表格行的高度');
var td1 = prompt('请输入单元格1的内容');
var td2 = prompt('请输入单元格2的内容');
var table = '<table bgcolor="' + bgColor + '" border="' + border + '" width="' + width + '" align="' + align + '">'
table += ' <tr height="' + height + '">'
table += ' <td>' + td1 + '</td>'
table += ' <td>' + td2 + '</td>'
table += ' </tr>'
table += '</table>'
document.write(table);
</script>
</body>
</html>
这里说一个小窍门,动态生成表格的拼接字符串可以先在body中生成你想要的表格,然后将其连同缩进也都一行一行复制过来,这样能看的清晰,每一行的变量用+=相连接。 这里手动输入测试的数据依次是:green、1、500、center、50、111、111。 输出结果:
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/219052.html原文链接:https://javaforall.cn
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有