检查现有 Cookie 无法正常工作

Checking for the existing cookies doesn't work properly

本文关键字:常工作 工作 Cookie 检查      更新时间:2023-09-26

我想触发点击我的视频以显示页面何时具有特定的cookie。但无论出于何种原因,它对我都不起作用,我是 jQuery 的新手,将感谢您的帮助。

这是我的代码(要查看完整的代码,请在工作 JSFIDDLE 上

jQuery(document).ready(function($) {
        jQuery('.video-thumb').click(function() {
            var vidId = $(this).attr('id');
            var vidBg = $(this).attr('data-bg');
            $('#container').html('<iframe data-color="'+vidBg+'" id="player_'+vidId+'" width="420" height="315" src="http://www.youtube.com/embed/' + vidId + '?enablejsapi=1&autoplay=1&autohide=1&showinfo=0" frameborder="0" allowfullscreen></iframe>');
            });
        });
    if (getCookie('username') && getCookie('temp')) {
            $( ".initial" ).click();
            aler('Cookies are set');
      }

我不确定你想做什么,但是在你的小提琴中,你只放置了cookie"用户名",你从未设置cookie"temp",所以这不会执行,因为"临时"cookie不存在:

if (getCookie('username') && getCookie('temp')) {
    $( ".initial" ).click();
    alert('Cookies are set');
}

如果您只在寻找您应该使用的 cookie 之一

if (getCookie('username') || getCookie('temp')) {
    $( ".initial" ).click();
    alert('Cookies are set');
}