私たちは
PHP と Javascript の対話方法、つまり Cookie を介した対話を使用しています。合計 3 つのファイルがあります:
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 プログラムを制御することもできます。
PHPとJavascriptの相互作用の実装コード:
<ol class="dp-xml"> <li class="alt"><span><span class="tag"><</span><span> </span><span class="tag-name">html</span><span class="tag">></span><span> </span></span></li> <li> <span class="tag"><</span><span> </span><span class="tag-name">head</span><span class="tag">></span><span> </span> </li> <li class="alt"> <span class="tag"><</span><span> </span><span class="tag-name">title</span><span class="tag">></span><span>Test</span><span class="tag"><</span><span> /title</span><span class="tag">></span><span> </span> </li> <li> <span class="tag"><</span><span> </span><span class="tag-name">meta</span><span> </span><span class="attribute">http-equiv</span><span>=</span><span class="attribute-value">"Content-Type"</span><span> <br /></span><span class="attribute">content</span><span>=</span><span class="attribute-value">"text/html; charset=gb2312"</span><span class="tag">></span><span> </span> </li> <li class="alt"> <span class="tag"><</span><span> /head</span><span class="tag">></span><span> </span> </li> <li> <span class="tag"><</span><span> </span><span class="tag-name">frameset</span><span> </span><span class="attribute">framespacing</span><span>=</span><span class="attribute-value">"0"</span><span> <br /></span><span class="attribute">border</span><span>=</span><span class="attribute-value">"false"</span><span> </span><span class="attribute">frameborder</span><span>=</span><span class="attribute-value">"0"</span><span> </span><span class="attribute">cols</span><span>=</span><span class="attribute-value">"0,*"</span><span class="tag">></span><span> </span> </li> <li class="alt"> <span class="tag"><</span><span> </span><span class="tag-name">frame</span><span> </span><span class="attribute">name</span><span>=</span><span class="attribute-value">"leftFrame"</span><span> </span><span class="attribute">scrolling</span><span>=</span><span class="attribute-value">"no"<br /></span><span> noresize </span><span class="attribute">src</span><span>=</span><span class="attribute-value">"action.php"</span><span class="tag">></span><span> </span> </li> <li> <span class="tag"><</span><span> </span><span class="tag-name">frame</span><span> </span><span class="attribute">name</span><span>=</span><span class="attribute-value">"rightFrame"</span><span> </span><span class="attribute">scrolling</span><span>=</span><span class="attribute-value">"auto"</span><span> <br /></span><span class="attribute">src</span><span>=</span><span class="attribute-value">"main.htm"</span><span class="tag">></span><span> </span> </li> <li class="alt"> <span class="tag"><</span><span> /frameset</span><span class="tag">></span><span class="tag"><</span><span> </span><span class="tag-name">noframes</span><span class="tag">></span><span> </span> </li> <li> <span class="tag"><</span><span> </span><span class="tag-name">body</span><span> </span><span class="attribute">bgcolor</span><span>=</span><span class="attribute-value">"#FFFFFF"</span><span class="tag">></span><span> </span> </li> <li class="alt"> <span class="tag"><</span><span> </span><span class="tag-name">p</span><span class="tag">></span><span>本页使用页面框架,但是您的浏览器不支持。</span><span class="tag"><</span><span> /p</span><span class="tag">></span><span> </span> </li> <li> <span class="tag"><</span><span> /body</span><span class="tag">></span><span> </span> </li> <li class="alt"> <span class="tag"><</span><span> /noframes</span><span class="tag">></span><span> </span> </li> <li> <span class="tag"><</span><span> /html</span><span class="tag">></span><span> </span> </li> <li class="alt"> <span class="tag"><</span><span> ? </span></li><li><span>srand((double)microtime()*1000000); </span></li><li class="alt"><span>$</span><span class="attribute">result</span><span>=</span><span class="attribute-value">rand</span><span>(0,100); </span></li><li><span>setcookie("action",$result,time() 900,"/"); </span></li><li class="alt"><span class="tag">?></span><span> </span> </li> </ol>
以上がPHPとJavaScriptの相互作用の具体的な実装方法です。