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

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

方法一:通過Cookie交互。
一共是三個文件,分別為:index.htm,action.php,main.htm
原理為前臺頁面main.htm和后臺action.php通過頁面框架 index.htm組織起來,將action.php的頁面寬度設(shè)為0,這樣并不影響顯示。action.php將信息放入cookie中,main.htm通過讀取 cookie來實(shí)現(xiàn)交互。在main.htm中也可以通過重新讀取action.php 來實(shí)現(xiàn)控制后臺CGI程序。
index.htm
復(fù)制代碼 代碼如下:
<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
復(fù)制代碼 代碼如下:
<?php
srand((double)microtime()*1000000);
$result=rand(0,100);
setcookie("action",$result,time()+900,"/");
?>

main.htm
復(fù)制代碼 代碼如下:
<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" >
當(dāng)前參數(shù)為<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.*.*來實(shí)現(xiàn)交互。
一共是三個文件,分別為:index.htm,action.php,main.htm,其中index.htm和前面的一樣。
原理為通過parent.rightFrame.test.current_cookie.value直接傳遞信息。
action.php
復(fù)制代碼 代碼如下:
<?
srand((double)microtime()*1000000);
$result=rand(0,100);
?>
<script language="Javascript">
parent.rightFrame.test.current_cookie.value="<? echo $result?>";
</script>

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

php技術(shù)php后臺程序與Javascript的兩種交互方式,轉(zhuǎn)載需保留來源!

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

主站蜘蛛池模板: 基隆市| 通城县| 修文县| 邯郸市| 合水县| 耿马| 包头市| 保山市| 平顺县| 苏尼特左旗| 陕西省| 揭西县| 措勤县| 祁门县| 沂源县| 吉安县| 阳谷县| 兖州市| 宝鸡市| 北海市| 武隆县| 尉氏县| 德安县| 原平市| 千阳县| 大邑县| 沽源县| 兴隆县| 乐昌市| 项城市| 新津县| 秭归县| 翼城县| 天津市| 油尖旺区| 石门县| 丰顺县| 富平县| 郁南县| 井陉县| 天祝|