0
我已经复制了一些代码以弹出可以正常工作的Bootstrap模式。但是,我想禁用背景,并且从我的研究中我需要将data-backdrop='static'
添加到我的按钮。据我所知,我已经做得正确,但似乎没有工作。不确定在哪里把data-backdrop ='static'?
JS代码使用modal.toggle来显示模式,所以我不知道我会把它放在JS代码中。
这是我的按钮的代码:
<a href="@Url.Action("DependentDetail", "Home", new { rid = item.RID })"
class="modal-link btn btn-sm btn-primary" data-backdrop="static">
<i class="glyphicon glyphicon-edit"></i>
Verify
</a>
这是我的JS代码:
$(function() {
// Attach modal-container bootstrap attributes to links with .modal-link class.
// when a link is clicked with these attributes, bootstrap will display the href content in a modal dialog.
$('body').on('click', '.modal-link', function (e) {
e.preventDefault();
$(this).attr('data-target', '#modal-container');
$(this).attr('data-toggle', 'modal');
});
// Attach listener to .modal-close-btn's so that when the button is pressed the modal dialog disappears
$('body').on('click', '.modal-close-btn', function() {
$('#modal-container').modal('hide');
});
//clear modal cache, so that new content can be loaded
$('#modal-container').on('hidden.bs.modal', function() {
$(this).removeData('bs.modal');
});
$('#CancelModal').on('click', function() {
return false;
});
});
UPDATE
$('body').on('click', '.modal-link', function (e) {
e.preventDefault();
$(this).attr('data-target', '#modal-container');
$(this).attr('data-toggle', 'modal');
$(this).attr('backdrop', 'true');
})
感谢。这在代码片段中起作用,所以我只需要将它合并到我现有的jQuery中即可。我将它添加为数据目标和数据切换的“attr”,但似乎不起作用。它会调出模态,但背景没有改变颜色。查看原始帖子中的更新代码。你知道我将jQuery代码中的背景设置放在哪里吗? – Caverman
$(this).attr('backdrop','true');使其为false –
或写入新的脚本标记并放入该代码 –