2011-12-06 36 views
0

我想显示弹出页面加载,不得不在弹出一个复选框字段,我想如果复选框被选中该页面只应是可见的。问题在于它在点击功能上运行良好,但无法使其在复选框上工作。这是我的代码jQuery的弹出窗口的onload

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.js"></script> 

<script type="text/javascript"> 
$(document).ready(function() { 

    var id = '#dialog'; 

    //Get the screen height and width 
    var maskHeight = $(document).height(); 
    var maskWidth = $(window).width(); 

    //Set heigth and width to mask to fill up the whole screen 
    $('#mask').css({'width':maskWidth,'height':maskHeight}); 

    //transition effect  
    $('#mask').fadeIn(1000);  
    $('#mask').fadeTo("slow",0.8); 

    //Get the window height and width 
    var winH = $(window).height(); 
    var winW = $(window).width(); 

    //Set the popup window to center 
    $(id).css('top', winH/2-$(id).height()/2); 
    $(id).css('left', winW/2-$(id).width()/2); 

    //transition effect 
    $(id).fadeIn(2000);  

    //if close button is clicked 
     if ($('.window .close').attr('checked')==true){ 
    function (e) { 
    //Cancel the link behavior 
    e.preventDefault(); 

    $('#mask').hide(); 
    $('.window').hide(); 
     }};  

     //if mask is clicked 
    $('#mask').click(function() { 
     $(this).hide(); 
    $('.window').hide(); 
     });  

     }); 

    </script> 


    <div style="font-size: 10px; color: rgb(204, 204, 204);">lorem ipsum</div> 

    <div id="boxes"> 
<div style="top: 199.5px; left: 551.5px; display: none;" id="dialog" class="window"> 
Simple Modal Window | 
<input type="checkbox" class="close"> 
</div> 
<!-- Mask to cover the whole screen --> 
<div style="width: 1478px; height: 602px; display: none; opacity: 0.8;" id="mask"> </div> 
</div> 
+2

请张贴简洁的代码示例,因为这将帮助那些谁是回答你的问题。 –

回答

1

尝试阅读本fancybox。这很棒,你可以打开弹出框并选中复选框。

0

无法completely..so你需要它,如果用户点击了面具消失的复选框,页面显示出来就好理解了你的问题?

做你的显示在面具的顶部,因为有一个在div..if的z-index的任何一个细节它不改变代码

$('#mask, .close').click(function() { 
    . 
    . 

得到它的工作...

0

你应该改变你的代码如下:

$(document).ready(function() { 

var id = '#dialog'; 

//Get the screen height and width 
var maskHeight = $(document).height(); 
var maskWidth = $(window).width(); 

//Set heigth and width to mask to fill up the whole screen 
$('#mask').css({'width':maskWidth,'height':maskHeight}); 

//transition effect  
$('#mask').fadeIn(1000);  
$('#mask').fadeTo("slow",0.8); 

//Get the window height and width 
var winH = $(window).height(); 
var winW = $(window).width(); 

//Set the popup window to center 
$(id).css('top', winH/2-$(id).height()/2); 
$(id).css('left', winW/2-$(id).width()/2); 

//transition effect 
$(id).fadeIn(2000);  

//if close checbox is checked 
    if ($('.window .close').attr('checked')==false){ 

    $('#mask').hide(); 
    $('.window').hide(); 

    }; 

    //if close checkbox is clicked 
    $('.window .close').click(function(){ 

     if(!$(this).is(":checked")){ 
     $('#mask').hide(); 
     $('.window').hide(); 
     } 

    });  

    //if mask is clicked 
    $('#mask').click(function() { 
     $(this).hide(); 
     $('.window').hide(); 
    });  

}); 

您应该添加复选框属性“检查”。

<input type="checkbox" class="close" checked="checked"> 
+0

这不会工作 - >怎么是'如果($()ATTR( '检查 ')==真' 窗口.close。'){'去工作过的唯一评价onDomReady – ManseUK

+0

你是对的。我改变了我的代码。 –

0

它似乎是你正在寻找一个事件被触发时,复选框被选中?

如果是这样,则函数应该有复选框的click事件

//if close button is clicked 
    $('.window .close').click(function(){ 
     if ($(this).attr('checked')==true) 
     { 
     //Cancel the link behavior 
     e.preventDefault(); 

     $('#mask').hide(); 
     $('.window').hide(); 
     } 
    });  
0

你关闭功能是不是有效的JavaScript:

//if close button is clicked 
if ($('.window .close').attr('checked')==true){ 
    function (e) { 
    //Cancel the link behavior 
    e.preventDefault(); 

    $('#mask').hide(); 
    $('.window').hide(); 
}};  

你可以同时取出点击活动,并与更换单个代码块 - >

$('#dialog .close, #mask').click(function(e){ //listen for clicks on the mask and close checkbox 
    $('#mask').hide(); // hide the mask 
    $('#dialog').hide(); // hide the dialog div 
}); 

工作示例:http://jsfiddle.net/4Mpb3/2/