博主信息
博文 41
粉丝 2
评论 1
访问量 32470
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
0413作业
郭恒的博客
原创
730人浏览过

生成带有标题的表格

实例 页面

<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
        <style>
            h3{
                color: red;
            }
            button{
                width: 60px;
                height: 20px;
                border: none;
                background-color: blue;
                color: white;
                margin-left: 20px;
            }
        </style>
    </head>
    <body>
<!--        <table>
            <tr>
                <th colspan="" rowspan=""></th>
            </tr>
        </table>-->
        <h3>我的表格生成器</h3>
        <p>标题:<input type="text" name="name" ></p>
        <p>行数:<input type="text" name="rows" ></p>
        <p>列数:<input type="text" name="cols" ></p>
        <p><button>生成</button><button>重置</button></p>
        <script src="js/jquery-1.8.0.min.js" type="text/javascript"></script>
        <script>
            //创建请求标志,防止重复请求
            var flag = true;
            $('button:first').on('click', function () {
//            alert(12)测试
                $(':input').eq(1).not('button').each(function (index, obj) {
                    if ($(obj).val().length == 0) {
                        $(obj).after('<span>不能为空</span>')
                        setTimeout(function () {
                            $(obj).next().remove()
                        }, 1000)
                        return false;
                    } else if (isNaN($(obj).val())) {
                        $(obj).after('<span>必须为数字</span>')
                        setTimeout(function () {
                            $(obj).next().remove()
                        }, 1000)
                        return false;
                    } else if ($(obj).val() <= 0) {
                        $(obj).after('<span>不能为0</span>')
                        setTimeout(function () {
                            $(obj).next().remove()
                        }, 1000)
                        return false;
                    }
                    //处理用户请求 ajax
                    if (flag == true) {
                        $.get('0413_2.php', {
                            rows: $('input[name = "rows"]').val(),
                            cols: $('input[name = "cols"]').val(),
                            name: $('input[name = "name"]').val()
                        }, function (data) {
                            $('p:last').next().remove()//用于清理上一个表格的内容
                            $('p:last').after(data)
                            flag = false;
                        })
                    }
                })
            })
            $('button').eq(1).click(function () {
                $(':input').not('button').val('')
                $(':input:first').focus()
                $('p:last').next().remove()
                flag = true
            })
        </script>
    </body>

</html>

运行实例 »

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

实例 PHP

<?php

if ($_SERVER['REQUEST_METHOD'] == 'GET') {
    if (!empty($_GET['rows']) && !empty($_GET['cols'])) {
        $rows = $_GET['rows'];
        $cols = $_GET['cols'];
        $name = $_GET['name'];
        $table = '<table border="1" cellspacing="0" cellpadding="3" align="center" width="80%" >';
        $table .= '<tr align="center" bgcolor="blue" >';     
        $table .= '<th colspan='.$cols.'>'.$name.'</th>'; 
        $table .= '</tr>';
//        echo $table;
        for ($g = 0; $g < $rows; $g++) {
            for ($f = 0; $f < $cols; $f++) {
                $df = $g*$cols+$f;
                $table .= '<td align="center">'.++$df.'</td>';
            }
            $table .='</tr>';
        }
        $table .= '<table>';
        echo $table;
    }
} else {
    exit('<span >非法请求</span>');
}
/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

运行实例 »

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


批改状态:合格

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

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

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