<html>
<head>
<script type="text/javascript">
function getCookie(c_name)
{
if (document.cookie.length>0)
{
c_start=document.cookie.indexOf(c_name + "=")
if (c_start!=-1)
{
c_start=c_start + c_name.length+1
c_end=document.cookie.indexOf(";",c_start)
if (c_end==-1) c_end=document.cookie.length
return unescape(document.cookie.substring(c_start,c_end))
}
}
return ""
} function setCookie(c_name,value,expiredays)
{
var exdate=new Date()
exdate.setDate(exdate.getDate()+expiredays)
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toGMTString())
} function checkCookie()
{
username=getCookie('username')
if (username!=null && username!="")
{alert('Welcome again '+username+'!')}
else
{
username=prompt('Please enter your name:',"")//prompt() 方法用于显示可提示用户进行输入的对话框。
if (username!=null && username!="")
{
setCookie('username',username,365)
}
}
}
</script>
</head> <body onLoad="checkCookie()">
</body>
</html>
//prompt(text,defaultText)方法用于显示可提示用户进行输入的对话框。
<html>
<head>
<script type="text/javascript">
function disp_prompt()
{
var name=prompt("Please enter your name","")
if (name!=null && name!="")
{
document.write("Hello " + name + "!")
}
}
</script>
</head>
<body> <input type="button" onclick="disp_prompt()"
value="Display a prompt box" /> </body>
</html>
//dateObject.setDate(day)方法用于设置一个月的某一天。day 必需,表示一个月中的一天的一个数值(1 ~ 31)。
//我们通过 setDate() 方法把当前月的天设置为 15:
<html>
<body> <script type="text/javascript"> var d = new Date()
d.setDate(15)
document.write(d) </script> </body>
</html>
//dateObject.toGMTString()方法可根据格林威治时间 (GMT) 把 Date 对象转换为字符串,并返回结果。
<html>
<body> <script type="text/javascript"> var d = new Date()
document.write (d.toGMTString()) </script> </body>
</html>
//结果:Thu, 13 Nov 2014 01:51:26 GMT
//stringObject.indexOf(searchvalue,fromindex)方法可返回某个指定的字符串值在字符串中首次出现的位置。
//searchvalue 必需。规定需检索的字符串值。 fromindex 可选的整数参数。规定在字符串中开始检索的位置。它的合法取值是 0 到 stringObject.length - 1。如省略该参数,则将从字符串的首字符开始检索。
<html>
<body> <script type="text/javascript"> var str="Hello world!"
document.write(str.indexOf("Hello") + "<br />")
document.write(str.indexOf("World") + "<br />")
document.write(str.indexOf("world")) </script> </body>
</html>
//结果:0 -1 6

注释:indexOf() 方法对大小写敏感!

注释:如果要检索的字符串值没有出现,则该方法返回 -1。

 

js的cookie操作及知识点详解的更多相关文章

  1. JS中的函数节流throttle详解和优化

    JS中的函数节流throttle详解和优化在前端开发中,有时会为页面绑定resize事件,或者为一个页面元素绑定拖拽事件(mousemove),这种事件有一个特点,在一个正常的操作中,有可能在一个短的 ...

  2. Activity知识点详解

    Activity知识点详解 一.什么是Activity 官方解释: The Activity class is a crucial component of an Android app, and t ...

  3. JS封装cookie操作函数实例(设置、读取、删除)

    本文实例讲述了JS封装cookie操作函数.分享给大家供大家参考,具体如下: ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 ...

  4. IOS数据库操作SQLite3使用详解(转)

    iPhone中支持通过sqlite3来访问iPhone本地的数据库.具体使用方法如下1:添加开发包libsqlite3.0.dylib首先是设置项目文件,在项目中添加iPhone版的sqlite3的数 ...

  5. [转]使用python来操作redis用法详解

    转自:使用python来操作redis用法详解 class CommRedisBase(): def __init__(self): REDIS_CONF = {} connection_pool = ...

  6. 最详尽的 JS 原型与原型链终极详解,没有「可能是」。(一)

    最详尽的 JS 原型与原型链终极详解,没有「可能是」.(一) 第二篇已更新,点击进入第三篇已更新,点击进入

  7. Node.js中环境变量process.env详解

    Node.js中环境变量process.env详解process | Node.js API 文档http://nodejs.cn/api/process.html官方解释:process 对象是一个 ...

  8. 转载 JS组件Bootstrap Select2使用方法详解

    JS组件Bootstrap Select2使用方法详解 作者:懒得安分 字体:[增加 减小] 类型:转载 时间:2016-01-26我要评论 这篇文章主要为大家介绍了JS组件Bootstrap Sel ...

  9. js replace 与replaceall实例用法详解

    这篇文章介绍了js replace 与replaceall实例用法详解,有需要的朋友可以参考一下stringObj.replace(rgExp, replaceText) 参数 stringObj 必 ...

随机推荐

  1. RDS 5.7三节点企业版时代的数据一致性解决方案

    上篇我们看到了在MySQL主备模式下,我们在数据一致性上做了不少事情,但解决方案都有一定的局限性,适合部分场景或者解决不彻底的问题.随着以Google Spanner以及Amazon Aruora 为 ...

  2. 洛谷1014 Cantor表

      水题.随便搞搞就过了. //Serene #include<algorithm> #include<iostream> #include<cstring> #i ...

  3. SWF在线绘本批量制作高质量PDF的新方法(重点在批量制作)

    SWF在线绘本批量制作高质量PDF的新方法(重点在批量制作) 2012-12-21  未来决定...       http://www.ebama.net/thread-107643-1-1.html ...

  4. C# 获取上传文件的文件名和后缀名

    //获得要上传的文件 HttpPostedFile file = Request.Files[]; //获得到文件名 string fileName = System.IO.Path.GetFileN ...

  5. 1-1.go开发工具安装

    (1) (2) bin:go的可执行文件 src:go的源代码 (3)安装开发工具 安装:goland-2018.1.1.exe 将.jar文件复制到工具的bin目录下   用记事本打开“goland ...

  6. 模板—FFT

    卷积:$C[i]=\sum \limits_{j=0}^{i}A[j]*B[i-j]$可以画图理解一下其实就是交叉相乘的和. 卷积可以看作两个多项式乘积的形式,只不过求出的结果的项数不同. FFT讲解 ...

  7. 检查进程启动情况,开始时间、启动时间、启动进程数、进程数是否正确、PID

    #!/bin/sh bin=$(cd ``;pwd) cd ${bin} ### 定义检查函数 chk(){ programName=$ correctNum=$ programSubName=$ # ...

  8. poj 1436 && zoj 1391 Horizontally Visible Segments (Segment Tree)

    ZOJ :: Problems :: Show Problem 1436 -- Horizontally Visible Segments 用线段树记录表面能被看见的线段的编号,然后覆盖的时候同时把能 ...

  9. Logback新版本报no applicable action for [Encoding]问题

    logback.xml配置文件如下: <?xml version="1.0" encoding="UTF-8"?> <configuratio ...

  10. 浮动,定位,flex布局

    什么是文档流 英文原文是:Normal flow. In CSS 2.1, normal flow includes block formatting of block-level boxes, in ...