亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

搜索
博主信息
博文 65
粉絲 3
評(píng)論 4
訪問(wèn)量 79593
最新下載
更多>
網(wǎng)站特效
網(wǎng)站源碼
網(wǎng)站素材
前端模板
php之遍歷表格,簡(jiǎn)直牛的一批
無(wú)恥的魚(yú)
原創(chuàng)
2170人瀏覽過(guò)
  • 1使用ajax給后臺(tái)發(fā)送數(shù)據(jù)

  • 2.后臺(tái)接收數(shù)據(jù)聽(tīng)通過(guò)for來(lái)遍歷 并返回給前臺(tái)

  • 3.使用success解析數(shù)據(jù)并展示在客戶端

下面是實(shí)例代碼

3.png

實(shí)例

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>數(shù)字表格</title>	
	<style type="text/css">
		div * {
			text-align: center;
		}
	</style>
</head>
<body>
		<fieldset>
			<legend>請(qǐng)大哥輸入</legend>
			標(biāo)題: <input type="text" id="txt"><br>
			行數(shù): <input type="number"><br>
			列數(shù): <input type="number"><br>
			<br>
			<button>生成</button>
			<button>重置</button>
		</fieldset>	
	<div></div>
</body>
<script type="text/javascript" src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script>
$(function(){
	//初始化
	var fage=true

	//點(diǎn)擊
	$('button:first').click(function()
	{
		if($('#txt').val().length == 0){
			alert('請(qǐng)大哥輸入標(biāo)題,謝謝!')
			$(this).val(' ')
			$(this).focus()
			return false

		}

		$('input[type="number"]').each(function(index,msg){
			//空與非數(shù)字判斷
		if($(msg).val().length==0){
			alert('請(qǐng)大哥輸入數(shù)字,謝謝!')
			$(this).val(' ')
			$(this).focus()
			return false
		}
		})

		if(fage == true){
	        $.ajax({
	        	//地址 php腳本文件 url:"dome.php",
	            url:"dome.php",
	            //數(shù)據(jù)
	            data:{name:$('input[type="text"]').val(),
	        		  rows:$('input[type="number"]').first().val(),
	        		  cols:$('input[type="number"]').last().val()},
	            type:"GET",//請(qǐng)求方法
	            success:function(data){
	                $('div').after(data)
	            }

	        })

	       fage = false 

       }
	})

	$('button:last').click(function(){

		$("input[type]").val(' ')
		$('table').remove() 

		fage=true

		$('#txt').focus()

	})
})	
</script>
</html>

運(yùn)行實(shí)例 ?

點(diǎn)擊 "運(yùn)行實(shí)例" 按鈕查看在線實(shí)例

//將下邊的代碼復(fù)制到一個(gè)文件 如 dome.php

實(shí)例


<?php
if($_SERVER['REQUEST_METHOD'] == 'GET'){
	if(!empty($_GET['rows']) && !empty($_GET['cols'])){
		$cols = $_GET['rows'];
		$rows = $_GET['cols'];
		$name = $_GET['name'];

		
		$table = '<table border="1" cellspacing="0" cellpadding="2" align="center" width="75%">';
		//標(biāo)頭
		$table .='<caption><h3>'.$name.'</h3></caption>';
		//標(biāo)題
		$table .='<tr align="center">' ;
		for($i = 0; $i < $cols; $i++ ){
			$table .= "<th>無(wú)</th>";
		}
		$table .="</tr>" ;
		//表格
		for($p = 0; $p < $rows; $p++ ){
			$table .="<tr>" ;
			for($k = 0; $k < $cols; $k++ ){
				$data = $p*$cols+$k;
				$table .= "<td>{$data}</td>";
			}
			$table .="</tr>" ;

		}

		$table .= "</table>";
		echo $table;
		exit();
	}
}

運(yùn)行實(shí)例 ?

點(diǎn)擊 "運(yùn)行實(shí)例" 按鈕查看在線實(shí)例



批改狀態(tài):合格

老師批語(yǔ):
本博文版權(quán)歸博主所有,轉(zhuǎn)載請(qǐng)注明地址!如有侵權(quán)、違法,請(qǐng)聯(lián)系admin@php.cn舉報(bào)處理!
全部評(píng)論 文明上網(wǎng)理性發(fā)言,請(qǐng)遵守新聞評(píng)論服務(wù)協(xié)議
1條評(píng)論
韋小寶 2018-04-16 10:28:09
的確是牛的一批?。
1樓
作者最新博文
關(guān)于我們 免責(zé)申明 意見(jiàn)反饋 講師合作 廣告合作 最新更新
php中文網(wǎng):公益在線php培訓(xùn),幫助PHP學(xué)習(xí)者快速成長(zhǎng)!
關(guān)注服務(wù)號(hào) 技術(shù)交流群
PHP中文網(wǎng)訂閱號(hào)
每天精選資源文章推送
PHP中文網(wǎng)APP
隨時(shí)隨地碎片化學(xué)習(xí)
PHP中文網(wǎng)抖音號(hào)
發(fā)現(xiàn)有趣的

Copyright 2014-2025 http://ipnx.cn/ All Rights Reserved | php.cn | 湘ICP備2023035733號(hào)

  • 登錄PHP中文網(wǎng),和優(yōu)秀的人一起學(xué)習(xí)!
    全站2000+教程免費(fèi)學(xué)