Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
399 views
in Technique[技术] by (71.8m points)

jquery - 关闭Bootstrap模态(Close Bootstrap Modal)

I have a bootstrap modal dialog box that I want to show initially, then when the user clicks on the page, it disappears.

(我有一个我想要最初显示的引导模式对话框,然后当用户点击页面时,它会消失。)

I have the following:

(我有以下内容:)

$(function () {
   $('#modal').modal(toggle)
});

 <div class="modal" id='modal'>
     <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
        <h3 id="myModalLabel">Error:</h3>
        </div>
        <div class="modal-body">
        <p>Please correct the following errors:</p>
        </div>
     </div>
 </div>

The modal is displayed initially, but it does not close when clicked outside of the modal.

(模态最初显示,但在模态外部单击时不会关闭。)

Also, the content area is not greyed out.. How can I get the modal to display initially, then close after the user clicks outside the area?

(此外,内容区域不会显示为灰色..如何让模式最初显示,然后在用户点击区域外关闭?)

And how can I get the background to be grayed out as in the demo?

(如何在演示中将背景变为灰色?)

  ask by Nick B translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Put modal('toggle') instead of modal(toggle)

(放置modal('toggle')而不是modal(toggle))

$(function () {
   $('#modal').modal('toggle');
});

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...