色尼玛亚洲综合影院,亚洲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的兩種交互方式,轉載需保留來源!

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

主站蜘蛛池模板: 顺平县| 开阳县| 泰顺县| 射阳县| 锡林浩特市| 蒙城县| 临武县| 开封县| 共和县| 乡宁县| 乐东| 麻阳| 当阳市| 霸州市| 双辽市| 岳阳市| 马山县| 东乌珠穆沁旗| 阿拉善盟| 鄢陵县| 沾益县| 安仁县| 集贤县| 望江县| 江都市| 通江县| 呈贡县| 当涂县| 绥中县| 竹山县| 安泽县| 合川市| 泽州县| 普宁市| 莫力| 南和县| 大悟县| 道孚县| 长子县| 景谷| 扎囊县|