开发者

auto pop up javascript...howto do with this code?

i want to do when user go to this page the javascript form will be auto-open,user don't need to click some button.

index.html:

<script>

$(document).ready(function() {  

    //select all the a tag with name equal to modal
    $('a[name=modal]').click(function(e) {
        //Cancel the link behavior
        e.preventDefault();

        //Get the A tag
        var id = $(this).attr('href');

        //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
    $('.window .close').click(function (e) {
        //Cancel the link behavior
        e.preventDefault();

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

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

});

</script>

And the HTML:

<div id="boxes">

<div id="dialog" class="window">
Simple Modal Window | 
<a href="#"class="close"/>Close it</a>
</div>

<!-- Start of Login Dialog -->  
<div id="dialog1" class="window">
  <div class="d-header">


  <form action="process.php" method="get">

    <input type="text" name="name" id="name" value="NAME " onclick="this.value=''"/><br/>
    <input type="text"  name="email"  id="email" value="E-MAIL " onclick="this.value=''"/>
    <input type="text"  name="contact" id="contact" value="CONTACT " onclick="this.value=''"/> 

    <select  name="program" id="program" /> 
    <option value=""  selected >PROGRAM - Select - </option>
        <option value="MEDICINE" >MEDICINE </option>
        <option value="DENTAL" onclick="this.value=''">DENTAL </option>
        <option value="PHARMACY" onclick="this.value=''">PHARMACY  </option>
    </select>

    <select type="text"  name="country"  id="country" /> 
      <option value="" selected="selected">COUNTRY - Select - </option>
         <option value="RUSSIA " >RUSSIA  </option>
        <option value="INDONESIA " >INDONESIA  </option>
        <option value="INDIA " >INDIA   </option>
    </select>


    <select type="text"  name="scholarship"  id="scholarship"/> 
    <option value="" selected="selected">SCHOLARSHIP - Select - </option>
       <option value="FULL " onclick="this.value=''">FULL  </option>
       <option value="PARTIAL " onclick="this.value=''">PARTIAL   </option>
    </select>
  </div>
  <div class="d-blank"></div>
  <div class="d-login"><input type="submit"  value="submit" style="margin-top:210px; margin-left:-120px;"/></div>
</div>
<!-- End of Login Dialog -->  



<!-- Start of Sticky Note -->
<div id="dialog2" class="window">
  So, with this <b>Simple Jquery Modal Window</b>, it can be in any shapes you want! Simple and Easy to modify : ) <br/><br/>
<input type="button" value="Close it" class="close"/>
</form>
</div>
</div>


just take away the $('a[name=modal]').click(function(e) { ... }) wrapper - and you might as well take away e.preventDefault() too as there is no event to prevent.


Just trigger a click event on one of the links. You won't have to write any new code, except for this one line:

$(document).ready()
{
    // Add this last
    $('a[name=modal]').eq(0).click();
});

This code clicks the first a[name=modal] automatically, so you won't have to modify and create new code just for auto-loading this thing.


Try adding this code:

$(document).ready()
{
    // Add this last
    $('a[href="#dialog1"]:eq(0)').click();
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜