我的按钮是
<button type="button" onclick="popUpSize();"
class="btn btn-primary" data-toggle="modal"
data-target="#myModal">
Launch demo modal
</button>
我的jQuery代码是
function popUpSize(){
var winHeight = $( window ).height();
var popHeight = winHeight - 200;
$('#myModal .modal-body').css('height', 'popHeight');
};
答案 0 :(得分:2)
popHeight
是一个不是字符串的变量,它不应该有引号。您也可以在shown.bs.modal
回调上调用此函数。您可以使用以下代码
$('#myModal').on('shown.bs.modal', function (e) {
// do something...
popUpSize();
})
function popUpSize(){
var winHeight = $( window ).height();
var popHeight = winHeight - 200;
$('#myModal .modal-body').css('height', popHeight);
};
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#myModal">Launch demo modal</button>