Help us understand the problem. What is going on with this article?

BootstrapのJavaScriptで、Modalを使うメモ(とても短いサンプル)

More than 3 years have passed since last update.

追記

スクリーンショット 2016-10-12 19.32.42.png

もう少し見やすく最小限にしてみたかったので、短くしました。 modal-dialog とかのクラスによって width がちょうどよく保たれるので、残してあります。

<div class="click_btn">
ここをClickするとモーダルが出る
</div>

<div class="modal fade" id="modal_box">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="box_inner">
        <p>
          てすとでーーーす
        </p>
        <p class="text-center"><a class="btn btn-primary" data-dismiss="modal" href="#">閉じる</a></p>
      </div>
    </div>
  </div>
</div>

<script>
$('.click_btn').on('click', function(){
  $('#modal_box').modal('show');
});
</script>

追記おわり


モーダルを気軽に表示しようとおもったら、Bootstrap:JavaScriptのモーダル使いますよね?

僕は使ったことないけど。

あほなメモです。ただ、静的なモーダルを表示するだけ。だけど、僕はこんなこともできなかったのです。

やること

<!-- ここはコピペ -->
<div class="modal fade">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
        <h4 class="modal-title">Modal title</h4>
      </div>
      <div class="modal-body">
        <p>One fine body&hellip;</p>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Save changes</button>
      </div>
    </div><!-- /.modal-content -->
  </div><!-- /.modal-dialog -->
</div><!-- /.modal -->

<!-- ここでscript -->
<script>
    jQuery(document).ready(function(){
        jQuery('.modal').modal('show');
    });
</script>

script部分は、readyを使って、ページが表示されたときにモーダルを出す!というだけです。この部分はいろいろ複雑にして、たのしみましょう。

ありがとうございました。

Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away