色尼玛亚洲综合影院,亚洲3atv精品一区二区三区,麻豆freexxxx性91精品,欧美在线91

php后臺程序與Javascript的兩種交互方式

方法一:通過Cookie交互。
一共是三個文件,分別為:index.htm,action.php,main.htm
原理為前臺頁面main.htm和后臺action.php通過頁面框架 index.htm組織起來,將action.php的頁面寬度設為0,這樣并不影響顯示。action.php將信息放入cookie中,main.htm通過讀取 cookie來實現交互。在main.htm中也可以通過重新讀取action.php 來實現控制后臺CGI程序。
index.htm
復制代碼 代碼如下:
<html>
<head>
<title>Test</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<frameset framespacing="0" border="false" frameborder="0" cols="0,*">
<frame name="leftFrame" scrolling="no" noresize src="action.php">
<frame name="rightFrame" scrolling="auto" src="main.htm">
</frameset><noframes>
<body bgcolor="#FFFFFF">
<p>本頁使用頁面框架,但是您的瀏覽器不支持。</p>
</body>
</noframes>
</html>

action.php
復制代碼 代碼如下:
<?php
srand((double)microtime()*1000000);
$result=rand(0,100);
setcookie("action",$result,time()+900,"/");
?>

main.htm
復制代碼 代碼如下:
<html>
<head>
<title>Test</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<script language="Javascript">
function get_cookie()
{
document.test.current_cookie.value=document.cookie;
}
</script>
</head>
<body bgcolor="#FFFFFF">
<form name="test" >
當前參數為<input type="text" name="current_cookie" size="80" maxlength="1000">
</form>
<script language="Javascript">
setInterval("get_cookie()",200);
</script>
<br>
<a href="action.php" target="leftFrame">重新讀取Cookie</a>
</body>
</html>

方法二:直接通過parent.*.*來實現交互。
一共是三個文件,分別為:index.htm,action.php,main.htm,其中index.htm和前面的一樣。
原理為通過parent.rightFrame.test.current_cookie.value直接傳遞信息。
action.php
復制代碼 代碼如下:
<?
srand((double)microtime()*1000000);
$result=rand(0,100);
?>
<script language="Javascript">
parent.rightFrame.test.current_cookie.value="<? echo $result?>";
</script>

main.htm
復制代碼 代碼如下:
<html>
<head>
<title>Test</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body bgcolor="#FFFFFF">
<form name="test" >
當前參數為<input type="text" name="current_cookie" size="80" maxlength="1000">
</form>
<br>
<a href="action.php" target="leftFrame">重新讀取Cookie</a>
</body>
</html>

php技術php后臺程序與Javascript的兩種交互方式,轉載需保留來源!

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

主站蜘蛛池模板: 利辛县| 洛宁县| 施甸县| 吉水县| 阿拉善左旗| 鄄城县| 洞头县| 乌兰县| 涞源县| 梧州市| 伊春市| 邮箱| 保山市| 侯马市| 高雄市| 珲春市| 黔西| 元谋县| 灌南县| 项城市| 屯昌县| 青海省| 女性| 镇巴县| 卫辉市| 陆河县| 务川| 大足县| 四会市| 瑞丽市| 肇州县| 尉犁县| 太谷县| 南部县| 辉县市| 马鞍山市| 冀州市| 康保县| 南京市| 黑山县| 璧山县|