博主信息
博文 36
粉丝 0
评论 1
访问量 34309
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
表格生成器
其琛的博客
原创
826人浏览过

代码如下:

    <!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>表格生成器</title>
<style type="text/css">
h2{
color:skyblue;
margin-left: 60px;
}
button{
border:none;
width: 90px;
height: 30px;
background-color: green;
color: white;
margin-left: 30px;
}
label{
margin-left: 30px;
}
button:hover{
font-size: 1.1em;
background-color: brown;
cursor: pointer;}
</style>
<script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){

$('button:first').on('click',function(){
var flag=true
$(':input').not('button').each(function(index,obj){
if($(obj).val().length==0){
if (index==0) {
$(obj).after('<span style="color:red">标题不能为空</span>')
}else{
$(obj).after('<span style="color:red">不能为空</span>')
}
setTimeout(function(){
$(obj).next().remove()
},2000)
return false
}else if(index>0){
if(isNaN($(obj).val())){
$(obj).after('<span style="color:red">必须为数字</span>')
setTimeout(function(){
$(obj).next().remove()
},2000)
return false
}
else if ($(obj).val()<=0) {
$(obj).after('<span style="color:red">必须大于零</span>')
setTimeout(function(){
$(obj).next().remove()
},2000)
return false
}else{
return true
}
}
})
if (flag==true) {
$.get('demo.php', {
caption:$('input[name="caption"]').val(),
rows:$('input[name="rows"]').val(),
cols:$('input[name="cols"]').val(),
}, function(data){
$('p:last').next().remove()
$('p:last').after(data)

flag=false
})
}
})
$('button:eq(1)').on('click',function(){
$('input').val("")
$(':input:first').focus()
$('p:last').next().remove()
flag=true

})

})
</script>
</head>
<body>
<p><h2>表格生成器</h2></p>
<p><label>标题:<input type="text" name="caption"></label></p>
<p><label>行数:<input type="text" name="rows"></label></p>
<p><label>列数:<input type="text" name="cols"></label></p>
<p><button>生成表格</button><button>重置表格</button></p>
</body>
</html>

后台代码:

<?php 
if ($_SERVER['REQUEST_METHOD'] == 'GET') {
	if (!empty($_GET['caption']) && !empty($_GET['rows']) && !empty($_GET['cols'])) {
		$caption = $_GET['caption'];
        $rows = $_GET['rows'];
        $cols = $_GET['cols'];
        $table = '<table border="1" cellspacing="0" cellpadding="3" align="left" width="80%"><tr bgcolor="#adff2f" align="center">';
        $table.="<caption>$caption</caption>";
        $table.='<tr align="center" bgcolor="#ccc">';
        for ($i=0; $i <$cols ; $i++) { 
        	$table.='<th>表头</th>';
        };
        $table.='</tr>';
        for ($r=0; $r <$rows ; $r++) { 
        	$table.='<tr>';
        	for ($c=0; $c < $cols; $c++) { 
        		$data=$r*$cols+$c;
        		$table.='<td align="center">'.++$data.'</td>';
        	}
        	$table .= '</tr>';
        }
        $table .= '</table>';
        echo "$table";
        exit();
}else{
	exit('<span style="color:red">请求类型错误</span>');
}
}

成品图:Q5GZO`J{FNAII09U@LJ2G0Y.png

批改状态:合格

老师批语:
本博文版权归博主所有,转载请注明地址!如有侵权、违法,请联系admin@php.cn举报处理!
全部评论 文明上网理性发言,请遵守新闻评论服务协议
0条评论
作者最新博文
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号

  • 登录PHP中文网,和优秀的人一起学习!
    全站2000+教程免费学