문제

다음을 달성하고 싶습니다.

  • 홈페이지로드에 모달 상자를 표시하십시오
  • 모달 박스 내에 단일 필수 확인란이있는 양식을 표시합니다.
  • 확인란을 확인하고, 제출 및 모달 박스를 닫고 홈페이지로 진행하십시오.
  • 쿠키를 사용 하여이 확인란 진드기 기본 설정을 기억하십시오
  • 사용자가 홈페이지로 돌아가서 확인란을 확인한 경우 모달 상자에 표시되지 않습니다.

나는 이것과 함께 어딘가에 가고있다 :

http://dev.iceburg.net/jquery/jqmodal

그 점에서 모달 상자를 페이지로드에 표시 할 수는 있지만 확인란을 필수하고 상자를 닫는 양식을 얻는 방법을 해결할 수는 없습니다. 또한 쿠키를 설정할 때 어디서부터 시작 해야할지 모르겠습니다.

모든 포인터는 대단히 감사 할 것입니다.

감사

편집 : 코드 포함 :

index.html- 페이지로드에 모달 상자를 표시합니다

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

    setTimeout($('#ex2').jqmShow(),2000); 

});

2.html- Ajax를 통해로드 된 모달 상자 컨텐츠

function validate(frm) {
        if (frm.checkbox.checked==false)
    {
        alert("Please agree to our Terms and Conditions.");
        return false;
    }
}


<form action="" method="POST" onSubmit="return validate(form);" name="form">
<input type="checkbox" name="checkbox" id="checkbox" value="1">&nbsp;I hereby agree to all Terms and Conditions</a>
<input type="submit" value="Submit">
</form>
도움이 되었습니까?

해결책

쿠키를 설정/읽을 수 있도록 jQuery 쿠키 플러그인을로드하십시오. http://plugins.jquery.com/project/cookie그럼 .. 아래에서 같은 것. 테스트되지 않았지만 아이디어를 얻습니다

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(); 
        }
    });
});

<form id="agreeFrm" action="" method="POST" name="form">
<input type="checkbox" name="checkbox" id="checkbox" value="1">&nbsp;I hereby agree to all Terms and Conditions</a>
<input type="submit" value="Submit">
</form>

다른 팁

얼마 전 jQuery 플러그인을 사용했습니다.

나는 그것이 얼마나 쉬운 지 매우 감동했습니다. 모달에는 여러 개의 확인란이 있었고 제출 버튼을 누른 후 모달이 켜진 페이지로 확인란의 값을 다시 가져 왔습니다.

모든 정보와 데모가 있습니다 단순 모달 홈페이지

마침내 작동합니다! 쿠키가 존재하고 쿠키의 가치를 중심으로 콜백이 누락되었습니다. 다음은 어떻게 생겼는지입니다. 분명한 실수가 있는지 알려주세요. (여러분의 지원에 감사드립니다)

function confirm(msg,callback) {
  $('#confirm')
    .jqmShow()
    .find('p.jqmConfirmMsg')
      .html(msg)
    .end()
    .find(':submit:visible')
      .click(function(){
        if(this.value == 'Proceed'){
           $.cookie("agreed_to_terms", '1', { expires : 1, path: '/' }); //set cookie, expires in 365 days
           (typeof callback == 'string') ?
            window.location.href = callback :
            callback();
        }
        $('#confirm').jqmHide();
      });
}


$().ready(function() {
  $('#confirm').jqm({overlay: 88, modal: 'true', trigger: false});

  // trigger a confirm whenever links of class alert are pressed.
  $('a.confirm').click(function() { 
    if ($.cookie('agreed_to_terms') == '1'){window.location.href = callback =
            callback()
       //they already have cookie set
    }else{
       confirm('About to visit: '+this.href+' !',this.href); 
    }
    return false;
  });
});// JavaScript Document
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top