【轉】bootstrap模態框(modal)使用remote方法載入資料,只能載入一次的解決辦法

來源:互聯網
上載者:User

標籤:

http://blog.csdn.net/coolcaosj/article/details/38369787bootstrap的modal中,有一個remote選項,可以動態載入頁面到modal-body中有兩種方法,一種是使用連結,另一種就是使用指令碼。

 

1 使用連結
<a href="user/userDetail.jsp" data-toggle="modal" data-target="#myModal">開啟對話方塊</a>

當點擊該串連時,userDetail.jsp的內容就可以動態載入到div.modal-body中。當然這裡的串連也可以是action

 

2 使用指令碼

 

 

[javascript] view plaincopyprint? 
  1. $("#myModal").modal({  
  2.     remote: "page.jsp"  
  3. });  


但是這樣載入後,會有問題,modal資料只載入一次,如果要載入不同的資料,例如根據id查詢不同物品的詳細資料,modal的資料是不能更新的,即使傳的id值不同。其實解決辦法很簡單,只需要在載入下次資料前,將之前的載入的資料清除即可。

 

清除之前載入的資料,讓對話方塊能夠在每次開啟時重新載入頁面

最簡單的方式就是監聽modal的hidden,當modal關閉時,即把資料清除即可:

[javascript] view plaincopyprint? 
  1. $("#myModal").on("hidden", function() {  
  2.     $(this).removeData("modal");  
  3. });  


也可以在每次開啟對話方塊之前移除資料,效果是一樣的。

註:上面的代碼基於 Bootstrap v2,如果使用 Bootstrape v3,模態對話方塊的 HTML 和事件的寫法有一些不同,例如對於上面的 hidden 事件,要寫成:

 

[javascript] view plaincopyprint? 
  1. $("#myModal").on("hidden.bs.modal", function() {  
  2.     $(this).removeData("bs.modal");  
  3. });  

 

參考:http://blog.csdn.net/a657941877/article/details/18145023

【轉】bootstrap模態框(modal)使用remote方法載入資料,只能載入一次的解決辦法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.