如何使用twitter bootstrap 3.1.1模态

时间:2014-03-12 00:12:06

标签: javascript jquery html css twitter-bootstrap

我已经看过很多模态的例子。但它们只能与bootstrap 2(css文件)完美配合 当我使用它与bootstrap 3.1.1 css文件。它不起作用。

<div class="container">
    <h2>Example of creating Modals with Twitter Bootstrap</h2>
    <div id="example" class="modal hide fade in" style="display: none; ">
         <div class="modal-header">
             <a class="close" data-dismiss="modal">×</a>
             <h3>This is a Modal Heading</h3>
         </div>
         <div class="modal-body">
             <h4>Text in a modal</h4>
             <p>You can add some text here.</p>             
         </div>
         <div class="modal-footer">
             <a href="#" class="btn btn-success">Call to action</a>
             <a href="#" class="btn" data-dismiss="modal">Close</a>
         </div>
    </div>
    <p>
        <a data-toggle="modal" href="#example" class="btn btn-primary btn-large">Launch demo modal</a>
    </p>
</div>

2 个答案:

答案 0 :(得分:4)

根据Bootstrap 3 documentation,您需要像这样构建HTML:

EXAMPLE HERE

<a class="btn btn-primary btn-large" data-toggle="modal" data-target=".modal">Launch demo modal</a>

<div class="modal fade">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
             <a class="close" data-dismiss="modal">×</a>
             <h3>This is a Modal Heading</h3>
         </div>
         <div class="modal-body">
             <h4>Text in a modal</h4>
             <p>You can add some text here.</p>             
         </div>
         <div class="modal-footer">
             <a href="#" class="btn btn-success">Call to action</a>
             <a href="#" class="btn" data-dismiss="modal">Close</a>
         </div>
        </div>
    </div>
</div>

答案 1 :(得分:2)

您缺少CSS类并且无效。主要问题是hide fade in

这是js fiddle link

<div class="container">
    <h2>Example of creating Modals with Twitter Bootstrap</h2>
    <div id="example" class="modal fade" style="display: none;">
        <div class="modal-dialog">
            <div class="modal-content">
            <div class="modal-header"> 
                <a class="close" data-dismiss="modal">×</a>
                 <h3>This is a Modal Heading</h3>
            </div>
            <div class="modal-body">
                <h4>Text in a modal</h4>
                <p>You can add some text here.</p>
            </div>
            <div class="modal-footer"> 
                <a href="#" class="btn btn-success">Call to action</a>
                <a href="#" class="btn" data-dismiss="modal">Close</a>
            </div>
            </div>
        </div>
    </div>
    <p> <a data-toggle="modal" href="#example" 
     class="btn btn-primary btn-large">Launch demo modal</a>
    </p>
</div>