jquery显示在关闭之前检查复选框是否已选中

时间:2014-07-09 07:25:15

标签: jquery html reveal.js

我正在使用jquery揭晓。这是我的一段代码:

<div id="myModal" class="reveal-modal" data-reveal>
            <p>bmla</p>
        <input id="read" type="checkbox" value="read">I've read it</input>
        <a id="ok" class="close-reveal-modal">OK</a>
    </div>

我想在关闭这个模态之前检查我的chebock是否已被检查..

$(document).ready(function(){
            if (/bla/.test(self.location.href)) {
                $('#myModal').reveal({
                    animation: 'fadeAndPop',                   //fade, fadeAndPop, none
                    animationspeed: 300,                       //how fast animtions are
                    closeonbackgroundclick: false
                });
            }
        });

我该怎么做?

提前致谢

1 个答案:

答案 0 :(得分:0)

尝试此操作:将点击事件绑定到'OK'链接并检查是否选中了复选框以关闭模式。并设置&#39; dismissmodalclass&#39;到任何其他类,以便点击OK时它不会关闭模态。

$(document).ready(function(){
          $('#ok').click(function(e){
             e.preventDefault();
             if($('#read').is(':checked'))
             {
              $('#myModal').trigger('reveal:close');
              return true;
             }
             else
             {
               alert('Please check the checkbox');
               return false;
             }
          });

       if (/bla/.test(self.location.href)) { 
          $('#myModal').reveal({
                    animation: 'fadeAndPop',                   //fade, fadeAndPop, none
                    animationspeed: 300,                       //how fast animtions are
                    closeonbackgroundclick: false,
                    dismissmodalclass: 'close-reveal-modal1' // class name changed to avoid close of modal on click of OK link
           });
       }
    });