Modal box + checkbox + cookie

后端 未结 3 1722
北海茫月
北海茫月 2021-01-03 14:34

I would like to achieve the following:

  • On homepage load, display modal box
  • Within modal box, display a form with a single mandatory checkbox
3条回答
  •  失恋的感觉
    2021-01-03 15:27

    Load the jquery cookie plugin to allow to set/read cookies: http://plugins.jquery.com/project/cookie then.. something like this below. Untested, but you get the idea

    index.html:

    $().ready(function() {
        if (!$.cookie('agreed_to_terms'))
        {
            $('#ex2').jqm({modal: 'true', ajax: '2.html', trigger: 'a.ex2trigger' });
            $('#ex2').jqmShow();    
        }
    });
    

    2.html:

    $().ready(function()
    {
        $('#agreeFrm').submit(function(e)
        {
            e.preventDefault();
    
            if ($(this).find('input[name=checkbox]').is(':checked'))
            {
                $.cookie('agreed_to_terms', '1', { path: '/', expires: 999999 });
                $('#ex2').jqmHide(); 
            }
        });
    });
    
    
     I hereby agree to all Terms and Conditions

提交回复
热议问题