亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

用于添加和編輯的一種模式引導程序 - Upsert

用于添加和編輯的一種模式引導程序 - Upsert

白衣染霜花 2023-09-21 10:07:22
我有 2 個鏈接(添加和編輯客戶表單),它們觸發一個相同的引導模式。我的問題是,同一個引導模式如何檢測它是來自“添加鏈接”或“編輯鏈接”?我當前的代碼是    <a href="" class="btn btn-default btn-rounded mb-4" data-toggle="modal" data-target="#modalCustomerForm">        Add New Customer    </a>$('#modalCustomerForm').on('shown.bs.modal', function () {    $(this).find('form')[0].reset();})
查看完整描述

1 回答

?
慕運維8079593

TA貢獻1876條經驗 獲得超5個贊

使用對象relatedTarget的屬性event來訪問觸發模態打開的元素


$('#exampleModal').on('shown.bs.modal', function(e){

   const buttonId = e.relatedTarget.id;

   $(this).find('.modal-body').text(`Button id = ${buttonId}`);      

});

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">


<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" ></script>

<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" ></script>


<!-- Button trigger modal -->

<button id="btn_1" type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal">

  Modal Button 1

</button>


<button id="btn_2" type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal">

  Modal Button 2

</button>


<!-- Modal -->

<div class="modal fade" id="exampleModal"  aria-hidden="true">

  <div class="modal-dialog" role="document">

    <div class="modal-content">

      <div class="modal-header">

        <h5 class="modal-title" id="exampleModalLabel">Modal title</h5>

        <button type="button" class="close" data-dismiss="modal" aria-label="Close">

          <span aria-hidden="true">&times;</span>

        </button>

      </div>

      <div class="modal-body"></div>     

    </div>

  </div>

</div>


查看完整回答
反對 回復 2023-09-21
  • 1 回答
  • 0 關注
  • 120 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號