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 –
或寫入新的腳本標記並放入該代碼 –