博主信息
博文 39
粉丝 0
评论 0
访问量 41516
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
表格自动生成器 4月13日作业
美丽城堡
原创
850人浏览过

实例

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>创造表格</title>
	<style>
		body{
			padding: 0;
			margin: 0;
		}
		.wrap{
			width: 960px;
			margin: auto;
		}
		header,footer{
			display: block;
			min-width: 960px;
			height: 88px;
			line-height: 88px;
			text-align: center;
			font-size: 28px;
			font-weight: 600;
			margin-bottom: 20px;
			box-shadow: 0 4px 20px -10px #ccc;
			overflow: hidden;
		}
		footer{
			box-shadow: 0 -4px 20px -10px #ccc;
			margin-top: 20px;
		}
		.box{
			padding: 16px;
		}
		.input{
			width: 200px;
			height: 40px;
			border: 1px solid;
			padding-left: 16px;
			font-size: 18px;
			border-radius: 4px;
		}
		.button input{
			display: inline-block;
			width: 100px;
			height: 40px;
			font-size: 18px;
			border: none;
			background: skyblue;
			border-radius: 6px;
			outline: none;
			margin-right: 12px;
            cursor: pointer;
		}
	</style>
</head>
<body>
	<header>创造表格</header>
	<article>
		<div class="wrap">
			<div class="box">
				<h2>动态创造表格</h2>
				
					<p class="title">
						<label for="tableTitle">请输入表格标题:</label>
						<input type="text" name="tableTitle" id="tableTitle" placeholder="标题" class="input">
					</p>
					<p class="rows">
						<label for="rows">请输入表格行数:</label>
						<input type="text" name="rows" id="rows" placeholder="大于零的整数" class="input">
					</p>
					<p class="cols">
						<label for="cols">请输入表格列数:</label>
						<input type="text" name="cols" id="cols" placeholder="大于零的整数" class="input">
					</p>
					<p class="button">
						<input type="submit" name="submit">
						<input type="reset" name="reset">
					</p>
					
			</div>
		</div>
	</article>
	<footer>End..</footer>

	<!-- <script src= "js/jquery-1.8.3.min.js"></script> -->
	<script src= "js/jquery-3.2.1.js"></script>
	<script>
		$(function(){
			var flag = true;;
			//输入框
			var input01 = $('p .input[name=tableTitle');
			var input02 = $('p .input[name=rows]');
            var input03 = $('p .input[name=cols]');
			console.log(input01);
            console.log(input02);
            console.log(input03);
			var submit = $('.button :submit').css("background","red");
			var reset = $('.button input[type=reset').css('background','green')

			
			input01.on('focus',function(){
				$(this).next().remove();

			})
			input02.on('focus',function(){
				$(this).next().remove();
			})
            input03.on('focus',function(){
                       $(this).next().remove();
                       })
			input01.on('blur',function(){
				if($(this).val().length == 0){
					$(this).after('<span style="color: red;">标题内容不能为空</span>');
				}
			})
			input02.on('blur',function(){
				if($(this).val().length == 0){
					$(this).after('<span style="color: red;">内容不能为空</span>');
				}else if(isNaN($(this).val()) || $(this).val() <= 0){
					$(this).after('<span style="color: red;">内容为大于零的整数</span>');
				}
			})
       		 input03.on('blur',function(){
				if($(this).val().length == 0){
					$(this).after('<span style="color: red;">内容不能为空</span>');
				}else if(isNaN($(this).val()) || $(this).val() <= 0){
					$(this).after('<span style="color: red;">内容为大于零的整数</span>');
				}
			})
			submit.on('click',function(){
                $('.button').next().remove();
				
				
					$.get(
						"a.php",
						{
							caption: input01.val(),
							row: input02.val(),
							col: input03.val()
						},
						function(res){
							$('.button').after(res);
						}
					)
					
				
			})
			reset.on('click',function(){
				$('.button').next().remove();
				input01.val('');
                input02.val('');
                input03.val('');
			})
			
		})

	</script>
</body>
</html>

运行实例 »

点击 "运行实例" 按钮查看在线实例


<?

if($_SERVER['REQUEST_METHOD'] == 'GET'){
	if(!empty($_GET['row']) && (!empty($_GET['col'])) && (!empty($_GET['caption']))){
		$caption = $_GET['caption'];
		$rows = $_GET['row'];
		$cols = $_GET['col'];
		$table = '<table border = "1" cellspacing="0" cellpadding= "4" align = "center" width="80%">';
		$table.='<caption>'.$caption.'</caption>';
		$table.='<tr align="cneter" bgcolor= "skyblue">';
		for($i = 0;$i<$cols;$i++){
			$table.='<th>'.$i.'</th>';
		} 
		$tabel.='</tr>';
		for($i=0;$i<$rows;$i++){
			$table.='<tr>';
			for($j= 0;$j<$cols;$j++){
				$table.='<td align = "center" bgcolor="skyblue">'.($i*$cols+$j).'</td>';
			}
		}
		$table.='</tr></table>';
		echo $table;
		exit();
	}
}else{
	exit('<span style="color: red;">请求类型错误</span>');
}

运行实例 »

点击 "运行实例" 按钮查看在线实例

运行图片:

aa.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+教程免费学