2014-07-09 147 views
0

我正在使用jquery显示。这是一张我的代码: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 
       }); 
      } 
     }); 

我怎样才能做到这一点?

在此先感谢

+0

请分享你的揭示模式初始化jquery。 –

+0

你的意思是? – user1345883

回答

0

试试这个:绑定click事件'OK'链接,如果复选框被选中或不关闭模式检查。并将'dismissmodalclass'设置为任何其他职业,以便点击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 
      }); 
     } 
    }); 
+0

这不起作用。当复选框没有被选中时,它仍然关闭 – user1345883

+0

可以请你分享这个jsfiddle,这样我可以帮助你更好的方式。 –

+0

查看我更新的答案。 –