js调用cookie

来源:互联网 发布:书记员速录软件 编辑:程序博客网 时间:2024/05/22 16:59

<?php 
setcookie("name", "Alex Porter", time()+3600);
?>
<html>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<body>
<!--<?php echo $_COOKIE["name"];?>-->
<script type="text/javascript">

function getCookie(name)
{
  var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
  if(arr != null) return unescape(arr[2]); 
  return null;
}

if(!getCookie("name"))
{
  alert('失败');  
}else{
 alert(getCookie("name"));
}
</script>

</body>
</html>

0 0