W3CAPI 实例工具箱
运行代码
源代码
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta charset="UTF-8"> <title>JavaScript : Retrieve values from a cookie - example1</title> </head> <body> <h1 style="color: red">JavaScript : Retrieve values from a cookie - example1</h1> <hr /> <script type="text/javascript"> //This is done to make the following JavaScript code compatible to XHTML. <![CDATA[ var search_cookie = "my_cookie" + "=" if (document.cookie.length > 0) { // Search for a cookie. offset = document.cookie.indexOf(search_cookie) if (offset != -1) { offset += search_cookie.length // set index of beginning of value end = document.cookie.indexOf(";",offset) if (end == -1) { end = document.cookie.length } alert(decodeURIComponent(document.cookie.substring(offset, end))) } } //]]> </script> </head> </body> </html>
运行结果
友情提示
您正在使用的浏览器为IE浏览器,或者使用了IE模式
如果你使用的是IE浏览器,建议您下载
360急速浏览器
/
火狐浏览器
/
Opera浏览器