jQuery simple multiple modals on one html page

江枫思渺然 提交于 2019-11-29 16:43:34

It should be easy for you unless you are not opening them simultaneously. Because the plugin uses id for it's containers and some elements in plugins. And having same id in a page will create issues in your code.

Here is the demo : http://jsfiddle.net/lotusgodkk/GCu2D/226/

HTML:

<div id='basic-modal'>
    <input type='button' name='basic' value='Demo' class='basic' />
    <div id="basic-modal-content1">Dialog 1</div>
    <input type='button' name='basic' value='Demo' class='basic' />
    <div id="basic-modal-content2">Dialog 2</div>
    <input type='button' name='basic' value='Demo' class='basic' />
    <div id="basic-modal-content3">Dialog 3</div>
</div>

jQuery:

$(document).ready(function () {
    $('#basic-modal .basic').click(function (e) {
        $(this).next('div').modal();
        return false;
    });
});

Code is pretty much clear. For every dialog instance, there is a separate div element which contains separate html. As far as the background is concerned, you can do it by giving CSS styles to the dialog containers.

For CSS,

This plugin provides an option for containerId which can be used for assigning custom Id to the container. Also you can use same ID for different CSS.

Demo: http://jsfiddle.net/lotusgodkk/GCu2D/227/

jQuery:

    $('#basic-modal .basic').click(function (e) {
    var c =  $(this).next('div');
    var id = c.attr('id')+'_c'; // create a custom Id.
    c.modal({
        containerId:id, 
    });
    return false;
});

CSS:

#basic-modal-content1_c{
    background-color:green;
}
#basic-modal-content2_c{
    background-color:red;
}
#basic-modal-content3_c{
    background-color:yellow;
}

In this way you can change the CSS. Please refer the customizable options of plugin. I am pretty sure you can use them for your purpose.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!