大雀软件园

首页 软件下载 安卓市场 苹果市场 电脑游戏 安卓游戏 文章资讯 驱动下载
技术开发 网页设计 图形图象 数据库 网络媒体 网络安全 站长CLUB 操作系统 媒体动画 安卓相关
当前位置: 首页 -> 技术开发 -> Script -> Javascript实例教程(5) 在一个表单中设置和检查Cookies

Javascript实例教程(5) 在一个表单中设置和检查Cookies

时间: 2021-07-31 作者:daque

cookie是第一小学段由欣赏器积聚起来扶助辨别用户身份的消息。在一个表单中树立和查看cookies的实行须要两个文献来实行。第一个文献为cookie1.html,这个文献须要有少许机理(底下例子的一个按钮)来查看能否有一个cookie生存,而后再重定向至表单网页大概文书档案载入网页。而第二个文献,即表单网页(cookie2.html),也是和要害的由于你将要在上头运用一点点javascript来树立cookie,这个树立是在提交表单之前做的。底下给出这文献:第一个文献(cookie1.html)<html><head><script language="javascript"><!--function cookieredirect(hascookieurl, nocookieurl){var currentcookie = document.cookie;if (currentcookie.indexof("formcomplete=yes") != -1) {window.location = hascookieurl;} else {window.location = nocookieurl;}}// --></script></head><body><form name="docdownload"><input type="button" value="download document"onclick="cookieredirect('doc.html', 'cookie2.html')"></form></body></html>第二个文献(cookie2.html ) <html><head><script language="javascript"><!--function sendform(objform){cookieexpires = "saturday, 01-jan-03 00:00:00 gmt";document.cookie = "formcomplete=yes; path=/";// objform.submit();}// --></script></head><body><form action="test.html" name="info"><table><tr><td>first name</td><td><input type="text" name="firstname"></td></tr><td>last name</td><td><input type="text" name="lastname"></td></tr><tr><td>address</td><td><input type="text" name="address"></td></tr><tr><td>city</td><td><input type="text" name="city"></td></tr><tr><td>state</td><td><input type="text" name="state"></td></tr><tr><td>zip</td><td><input type="text" name="zip"></td></tr></table><input type="button" value="download document"onclick="sendform(document.testform)"></form></body></html>底下再给出须要用到的doc.html文献:doc.html <html><body><h3>this is the document</h3></body></html>为了尝试一下这个功效,你不妨翻开cookie1.html并点击中按钮,你将被带回表单网页。即使你回到cookie1.html文献并点击按钮你就回直贯串到文书档案去。

热门阅览

最新排行

Copyright © 2019-2021 大雀软件园(www.daque.cn) All Rights Reserved.