【问题标题】:how to show different bootstrap modals on a single page如何在单个页面上显示不同的引导模式
【发布时间】:2020-01-28 21:16:06
【问题描述】:

我试图在一个页面上打开多个模式,但它们的 id 相互冲突。我从 bootstrap-4 文档中得到了这段代码,

模态 1 可以正常工作,但模态 2 无法工作,我希望它们两个单独工作

代码:

模态1

  <button type="button" class="btn btn-success" data-toggle="modal" data-target="#exampleModal">
                  Add New
                </button>

  <!-- Modal Add Owner -->
  <div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalLabel">Add Owner</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
        <form method="POST" action="{{ route('owner.store') }}">
        @csrf
          <div class="form-group">
            <label for="">Add Owner Name</label>
            <input type="text" name="owner_name" class="form-control" id="" placeholder="Owner Name">
          </div>
          <input type="submit" name="submit" class="btn btn-primary" value="submit">
        </form>  
      </div>
        <div class="modal-footer">
        </div>
      </div>
    </div>
  </div>

模态2:

<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal">
                      <a href="{{ route('owner.show', $owner->id)}}" class="btn btn-primary" data-toggle="modalshow" data-target="#exampleModalshow">Show</a>
                    </button>


  <!-- Modal Show Owner-->
  <div class="modal fade" id="exampleModalshow" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabe2" aria-hidden="true">
   <div class="modal-dialog" role="document">
     <div class="modal-content">
       <div class="modal-header">
         <h5 class="modal-title" id="exampleModalLabel">View Owner</h5>
         <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
        <form method="POST" action="{{ route('owner.update', $owner->id) }}">
        @csrf
        @method('PATCH')
          <div class="form-group">
            <label for="">Owner Name</label>
            <input type="text" name="owner_name" class="form-control" value="{{ $owner->owner_name }}">
          </div>
          <input type="submit" name="submit" class="btn btn-primary" value="submit">
        </form>  
      </div>
      <div class="modal-footer">
      </div>
    </div>
  </div>
 </div>

【问题讨论】:

  • 更改按钮数据目标与模态ID相同。

标签: laravel bootstrap-4 bootstrap-modal


【解决方案1】:

在第二个模态按钮上更改data-target 以匹配模态ID

<button data-target="#exampleModalshow">
   ... rest of the code
</button>

【讨论】:

  • 还是打不开?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-07-25
  • 2018-09-07
  • 2019-06-28
  • 1970-01-01
  • 2021-08-31
相关资源
最近更新 更多