JS學習筆記(模態框JS傳參)


 

博主最近基於django框架的平台第一版差不多完成了

今天整理下開發過程中遇到的前端知識

基於前端bootstrap框架模態框傳參問題

上前端html代碼:

 1       <div class="modal modal-info fade" id="modal-info">
 2           <div class="modal-dialog">
 3             <div class="modal-content">
 4               <div class="modal-header">
 5                 <button type="button" class="close" data-dismiss="modal" aria-label="Close">
 6                   <span aria-hidden="true">&times;</span></button>
 7                 <h4 class="modal-title">確認</h4>
 8               </div>
 9               <div class="modal-body">
10                 <p>是否確認運行任務</p>
11               </div>
12               <div class="modal-footer">
13                 <a href="#" class="btn btn-outline pull-left" id="path">確認</a>
14                 <button type="button" class="btn btn-outline " data-dismiss="modal">取消</button>
15               </div>
16             </div>
17             <!-- /.modal-content -->
18           </div>
19           <!-- /.modal-dialog -->
20       </div>
21       <!-- /.modal -->

上js代碼:

 

 1 <script>
 2 $('#modal-info').on('show.bs.modal', function (event) {  
 3     var btnThis = $(event.relatedTarget); //觸發事件的按鈕  
 4     var modal = $(this);  //當前模態框  
 5     var id = btnThis.data('id');   //解析出data-id的內容
 6     var path = '/run/{{ project_id }}/'+id;  //組裝路由
 7     console.log('taskId:', id);
 8     console.log('path:', path);
 9     document.getElementById("path").href=path; //給id=path的元素賦值href;
10 }); 
11 
12 </script>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM