2012-11-28 105 views
0

我經歷了所有可能的有關Twitter Bootstrap模式的問題,但我的問題在這裏是獨一無二的。Twitter bootstrap模式顯示,然後消失

我已經包括從最新發布的引導文件,所以我的公開目錄有 -

css/ 
| bootstrap.css 
| bootstrap.min.css 

js/ 
| bootstrap.js 
| bootstrap.min.js 

我也使用Select2,我已經檢查了它不與引導文件的干擾。

我的情態動詞是這樣定義的 -

<div class="modal hide fade" id="modal-<?php echo $user_role->id ?>" tabindex="-1" role="dialog" aria-hidden="true"> 
    <div class="modal-header"> 
     <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> 
     <h3>Update &ldquo;{{ $user_role->role_name }}&rdquo;</h3> 
    </div> 
    <div class="modal-body"> 
     <label>New Value</label> 
     <input type="hidden" name="inputId" value="<?php echo $user_role->id ?>"> 
     <input type="text" name="inputUpdate" value="<?php echo $user_role->role_name ?>" autofocus> 
    </div> 
    <div class="modal-footer"> 
     <a href="#" class="btn" data-dismiss="modal" aria-hidden="true">Cancel</a> 
     <a rel="update" href="<?php echo url('admin/dashboard/controls/update_master') ?>" class="btn btn-primary">Update</a> 
    </div> 
</div> 

,並調用模式,按鍵的定義如下 -

<a rel="edit" data-toggle="modal" href="#modal-<?php echo $user_role->id ?>" class="btn btn-info">Edit</a> 

在頁面上運行的JS是 -

$(document).ready(function() { 
    var urlModal; 
    $('a[rel="edit"]').click(function() { 
     urlModal = $(this).attr('href'); 
     $(urlModal).modal(); 
    }); 
}); 

每當我點擊<a rel="edit">按鈕,模態就會出現並立即消失。

+0

你試過$(urlModal).modal('show'); ? –

+0

只是解決了這個問題。非常愚蠢的我。讓我來解釋一下。 – Aniket

回答

3

我剛纔發現了這個問題。

$('a[rel="edit"]').click(function() { 
    urlModal = $(this).attr('href'); 
    $(urlModal).modal(); 
}); 

$(urlModal).modal();部分不是必需的。按鈕的HTML部分中的代碼本身會拍攝模式。這個查詢正在關閉它。

現在,它的工作。