admin管理员组文章数量:1353326
I have my code here, that inserts a predefined modal markup at the end of the body:
var languageModal =
'<div id="lngModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="lngModalLabel" aria-hidden="true">'+
' <div class="modal-body"></div>'+
' <div class="modal-footer">'+
' <form class="inline" id="lngModalForm">'+
' <button class="btn btn-primary" data-dismiss="modal" aria-hidden="true">'+
' <span lang="hu"'+((langAfterInit == 'hu') ? '' : ' style="display:none;"')+'>Bezárás</span>'+
' <span lang="en"'+((langAfterInit != 'hu') ? ' style="display:none;"' : '')+'>Close</span>'+
' </button>'+
' </form>'+
' </div>'+
'</div>';
$('body').append(languageModal);
But, when I call .modal()
on it, it won't load, only the black overlay appears:
$('#lngModal').modal({
backdrop : 'static',
keyboard : false,
remote : '/language.html',
});
I tried with .on('modal',{...})
, but that didn't work.
I have my code here, that inserts a predefined modal markup at the end of the body:
var languageModal =
'<div id="lngModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="lngModalLabel" aria-hidden="true">'+
' <div class="modal-body"></div>'+
' <div class="modal-footer">'+
' <form class="inline" id="lngModalForm">'+
' <button class="btn btn-primary" data-dismiss="modal" aria-hidden="true">'+
' <span lang="hu"'+((langAfterInit == 'hu') ? '' : ' style="display:none;"')+'>Bezárás</span>'+
' <span lang="en"'+((langAfterInit != 'hu') ? ' style="display:none;"' : '')+'>Close</span>'+
' </button>'+
' </form>'+
' </div>'+
'</div>';
$('body').append(languageModal);
But, when I call .modal()
on it, it won't load, only the black overlay appears:
$('#lngModal').modal({
backdrop : 'static',
keyboard : false,
remote : '/language.html',
});
I tried with .on('modal',{...})
, but that didn't work.
- sure you loaded the modal.js ? also, are you trying opening automatically the modal or opening that on btn click or somenthing like this? – Filippo oretti Commented Jan 1, 2013 at 20:39
- @Badaboooooom Allow me to share the js file: dropbox./s/osgkfcmqtm4p42v/init.js – SeinopSys Commented Jan 1, 2013 at 20:42
4 Answers
Reset to default 1try this:
$('body').append(languageModal,function(){
console.log('modal appended');
$('#lngModal').modal({
backdrop : 'static',
keyboard : false,
remote : '/language.html',
});
console.log('modal init');
});
instead of
$('body').append(languageModal);
$('#lngModal').modal({
backdrop : 'static',
keyboard : false,
remote : '/language.html',
});
Your code does work. Are you loading the bootstrap css?
http://jsfiddle/xjCAn/
I can't post this w/o some code:
' Nothing, really
After a lot of help from @Badaboooooom and @ic3b3rg, turns out I had to exchange the .modal({... remote : '...', ..})
for a data-remote="..."
tag in the script markup, and also had to remove the .fade
from #lngModal
.
var languageModal = '<div id="lngModal" class="modal hide" data-remote="/language.html">'+
//other stuff
$('#lngModal').modal('show',{
backdrop: true,
keyboard: false,
});
I had that also once, but only when I wanted to increase to modal size by using the following css:
var modal = $('#lngModal');
modal.css({
width: '60%',
left: '20%',
margin: 'auto auto auto auto',
top: '10%'
});
I fixed it by setting max-height
on the modal-body
:
var modalBody = modal.children('.modal-body');
modalBody.css({
maxHeight: '800px'
});
Did you change the modal css?
本文标签: javascriptUse bootstrap modal() on dynamically loaded contentStack Overflow
版权声明:本文标题:javascript - Use bootstrap .modal() on dynamically loaded content - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743915787a2561191.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论