简体   繁体   中英

Trigger html popup from js

In my JS i"ve got an IF condition. I want to be able to make a pop-up appear in my html page. How can I make the below pop up appear in javascript?

<a href="#x" class="overlay" id="welcome_message"></a>
     <div class="popup">
          <h2>Welcome</h2>
          <p>blah blah...</p>
     <div>
          <label for="name">Name</label>
          <input type="text" id="name" value=""/>
     </div>
</div>
prompt('Welcome\nblah blah...\n\nName');

would make a dialog box appear that says:

page. com says:

Welcome
blah blah...

Name ___________

Demo

\\n Creates a new line, and prompt takes user input.

Try this (jQuery):

$(document).on('click', '#welcome_message:not(.active)', function(){
    $(this).addClass('active');
    $('.popup').show();
    return false;
})
.on('click', '#welcome_message.active', function(){
    $(this).removeClass('active');
    $('.popup').hide();
    return false;
});

Use js plugin like bootstrap or modal pop up. These plugin will provide css and different functionality as well. Bootsrap

Edited

You can find demo at following link http://getbootstrap.com/javascript/#modals If still you are facing any problem please let me know.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM