javascript - 如何在模态显示之前刷新 Bootstrap 模态刷新

标签 javascript jquery twitter-bootstrap

我曾尝试在我的项目中使用多种模式,但只有一种模式加载数据。关闭模态后,我加载另一个模态。但无法加载该模态数据。那是加载的旧模态数据。如何解决这个问题?

这是我第一次加载 Jquery。此数据正常工作。

function Viewfull(id) {
    $.post('php/owner_list_view_modal.php',{id:id}, function (data) {
        var html = table(data);
         $('.modal-body').html(html);
         $('#orumodal').modal('show');
    });
}

function table(val) {
    var obj = $.parseJSON(val);

        var html = '<style>tr:nth-child(odd){background-color: #f5f5f5;} thead>tr{background-color: #ec971f; color: white;}</style>';
            html += '<table class="table table-bordered has-warning">';
                html += '<tbody>';
                    html += '<tr><td>Name</td><td>'+ obj.name +'</td></tr>';
                    html += '<tr><td>Email</td><td>'+ obj.emailid +'</td></tr>';
                    html += '<tr><td>Mobile</td><td>'+ obj.mobile +'</td></tr>';
                    html += '<tr><td>Address</td><td>'+ obj.address +'</td></tr>';
                    html += '<tr><td>Place</td><td>'+ obj.place +'</td></tr>';
                    html += '<tr><td>City</td><td>'+ obj.city +'</td></tr>';
                    html += '<tr><td>State</td><td>'+ obj.state +'</td></tr>';
                    html += '<tr><td>Pin</td><td>'+ obj.pin +'</td></tr>';
                    html += '<tr><td>Status</td><td>'+ obj.status +'</td></tr>';
                html += '</tbody>';
      return html += '</table>';
}

这是我单击第一个模态数据显示然后关闭该模态时的另一个模态。然后我点击另一个模态,我看到了第一个模态结果:

<div id="uploadimg" class="modal fade" role="dialog">
    <div class="modal-dialog modal-md">

        <!-- Modal content-->
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">&times;</button>
                <h4 class="modal-title"></h4>
            </div>
            <div class="modal-body" id="uploadmsg">
               <div class="container">
                   <div class="row well">
                       <div class="col-md-offset-4 col-md-6">
                           <form method="post" action="profile_image_save.php" enctype="multipart/form-data">
                               <div class="form-group">
                                   <label>Profile Image</label>
                                   <input type="file" id="profileimg" name="profileimg">
                               </div>
                               <div class="form-group">
                                   <button class="btn btn-success btn-lg pull-right">Change</button>
                               </div>
                           </form>
                       </div>
                   </div>
               </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
            </div>
        </div>

    </div>
</div>

最佳答案

you can use something like this to clear old data. Below your code $('#orumodal').modal('show'); Use any of the following:

$("#myModal").val(null).trigger("change");

$('#myModal').removeData();

删除除第一行以外的所有行:

$("#myModal").find("tr:not(:nth-child(1))").remove();

关于javascript - 如何在模态显示之前刷新 Bootstrap 模态刷新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41221794/

相关文章:

javascript - Disqus 评论系统 - 边距左偏移

php - 添加文本时停止闪烁(清除框并重新填充)的算法

twitter-bootstrap - 使用 Bootstrap v4-alpha-5 合理化 .btn-group

php - 有没有办法限制下拉框的大小

html - 响应时两个 Bootstrap 行未正确对齐

javascript - jQuery 过滤函数选择器错误

javascript - 具有 Backbone 结构的JSNI

javascript - C3.js气泡图选择

javascript - 单击 wordpress 链接时,如何让 JavaScript 识别?

javascript - 更改选择填充不需要的结果