【发布时间】:2015-06-03 16:20:30
【问题描述】:
我正在使用 Bootstrap 3 和数据表 1.9。当我单击数据表第一页中的锚标记时,模态已打开,但在使用数据表分页后显示 Bootstrap 模态时出现问题。如何解决这个问题。 这是我的代码
<html>
<body>
<table id=prodlist class="table table-bordered table-striped">
<thead>
<tr>
<th>#</th>
</tr>
</thead>
<tbody>
<tr>
<td> <a href="http://localhost/admin/product/viewProduct/15" class="prod-view" data-target="#modal" data-toggle="modal">edit</a>
</td>
</tr>
<tr><td>
<a href="http://localhost/admin/product/viewProduct/15" class="prod-view" data-target="#modal" data-toggle="modal">edit</a>
</td></tr>
<tr><td>
<a href="http://localhost/admin/product/viewProduct/15" class="prod-view" data-target="#modal" data-toggle="modal">edit</a>
</td> </tr>
</tbody>
</table>
</body>
</html>
我的数据表 javascript 是
$(function() {
$("#prodlist").dataTable({
"bAutoWidth": false,
"aoColumnDefs": [{
"sWidth": "5%",
"aTargets": [0],
"bSearchable": false,
"bSortable": false,
"bVisible": true
}, ]
});
});
if ($(".alert-success, .alert-error").length > 0) {
setTimeout(function() {
$(".alert-success, .alert-error").fadeOut("slow");
}, 1000);
}
$(document).ready(function(){
$(".prod-view").click(function(){
var href = $(this).attr('href');
$( ".modal-body" ).load( href );
$('#myModal').modal('toggle')
});
});
【问题讨论】:
-
您肯定没有显示您的真实代码。格式错误的标记永远不会生成带有工作模式的数据表。
-
我正在使用 php 和 Mysql。这里我只在表中显示了 3 行,但实际上我已经从 MySQL 中获取记录并显示在表中。我只在数据表的第二页遇到问题。我认为问题与DOM有关
-
由于引导模式不是可选的,所以它们也应该在第 2 页等上工作。我用上面的代码进行了测试,所有页面上都显示了模态,没有任何问题。如果您通过代码激活模态框,那将是另一回事,但您并没有这样做。
-
我也试过另一个例子,这也不起作用。你能在这里发布你的代码吗?提前致谢
标签: twitter-bootstrap datatables