Php 需要帮助设置cookie以记住按钮单击并禁用它X分钟吗
我试图让cookie在最后一次点击后记住按钮点击大约X分钟,即使重新加载页面,然后在点击X分钟后再次启用它,但我做不到,有人帮我吗? 这是设置限制代码,我已经完成了,我只需要有人为我设置cookiePhp 需要帮助设置cookie以记住按钮单击并禁用它X分钟吗,php,jquery,cookies,Php,Jquery,Cookies,我试图让cookie在最后一次点击后记住按钮点击大约X分钟,即使重新加载页面,然后在点击X分钟后再次启用它,但我做不到,有人帮我吗? 这是设置限制代码,我已经完成了,我只需要有人为我设置cookie (function(){ var click_counter = 0; jQuery('.button').on('click', function(event){ event.preventDefault(); var el = jQuery(thi
(function(){
var click_counter = 0;
jQuery('.button').on('click', function(event){
event.preventDefault();
var el = jQuery(this);
click_counter += 1;
if (!el.hasClass('inactive')){
// should be activated
};
if (click_counter >= 6){
// deactivate
el.addClass('inactive');
alert('Message');
};
});
})();
谢谢我想我明白了,我会这样做: 试试这个:
function writeCookie (key, value, mins) {
var date = new Date();
// Get unix milliseconds at current time plus number of hours
date.setTime(+ date + (mins * 3600000)); //60 * 60 * 1000
window.document.cookie = key + "=" + value + "; expires=" + date.toGMTString() + "; path=/";
return value;
};
用法:
<script>
writeCookie ("myCookie", "clicked", 2);
</script>
//for 2 mins
写博客(“我的博客”,“点击”,2);
//2分钟
我们希望在页面加载时检查:
<script>
$c_value = document.cookie;
if ($c_value == "clicked") {
// whatever you code to deactivate is
}
</script>
$c_value=document.cookie;
如果($c_值==“点击”){
//无论您要停用的代码是什么
}
您正在尝试。可以但是我不明白你的问题。为什么这句话的结尾有个问号?