年龄检查和jQuery [英] Age Check and jquery

查看:110
本文介绍了年龄检查和jQuery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有人有关于如何实现基于jQuery或javascript的年龄检查程序的可靠示例?我希望将某人打到一个页面上,当他们点击该站点上的任何页面时,他们每天至少需要输入一天,月份和年份.一旦他们确认为18岁,如果他们返回,直到第二天他们才会再次受到困扰.

Does anyone have any solid examples of how to implement a jQuery or javascript based age checker? I'm looking to send someone to a page where they need to enter in the Day, Month and Year at least once a day when they hit any page on the site. Once they validate as 18 then they would not be pestered again until the next day if they return.

有什么想法吗?

推荐答案

基于cookie的解决方案确实合乎逻辑,因为您可以从JavaScript中以编程方式对其进行修改,并且可以设置其过期时间.用纯JavaScript计算日期可以这样完成:

A cookie-based solution does seem a logical fit since you can programmatically modify them from JavaScript and you can set their expiry. Calculating the date in pure JavaScript can be done as such:

var millisPerYear = 1000 * 60 * 60 * 24 * 365;
var birthdate = new Date(year, month, day); // from user input.
var age = ((new Date().getTime()) - birthdate.getTime()) / millisPerYear;
// Now set the "age" cookie.

剩下的一切就是让服务器端响应处理程序根据来自请求代理的年龄" cookie的值有条件地返回内容.

All that is left is for your server-side response handlers to return content conditionally based on the value of the "age" cookie from the request agent.

这篇关于年龄检查和jQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆