简体   繁体   English

Twitter引导模式显示,然后消失

[英]Twitter bootstrap modal shows and then disappears

I went through all possible questions related to Twitter Bootstrap modals but my problem is kind of unique over here. 我经历了与Twitter Bootstrap模式有关的所有可能问题,但是我的问题在这里有点独特。

I have included the files from the latest bootstrap release, so my public directory has - 我已经包含了最新的引导程序发行版中的文件,因此我的公共目录包含-

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

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

I am also using Select2 and I have checked that it is not interfering with the bootstrap files. 我也在使用Select2,并且我检查了它是否不干扰引导文件。

My modals are defined this way - 我的模态是这样定义的-

<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>

And to call the modal, the button is defined like this - 为了调用模式,按钮的定义如下:

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

The JS that runs on the page is - 该页面上运行的JS是-

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

Whenever I click on the <a rel="edit"> button, the modal appears and immediately goes away. 每当我单击<a rel="edit">按钮时,模态就会出现并立即消失。

I just figured out the problem. 我只是想出了问题。

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

The $(urlModal).modal(); $(urlModal).modal(); part wasn't required. 部分不是必需的。 The code in the HTML part of the button, itself shoots the modal. 按钮的HTML部分中的代码本身就是模态。 And this query was closing it. 而这个查询正在关闭它。

Now, its working. 现在,它的工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM