Correction status:qualified
Teacher's comments:
<!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>'); }
点击 "运行实例" 按钮查看在线实例
运行图片: