示例:http://jsfiddle.net/atfb8huL/
....它会继续这样。
在加载内容之前,我不知道收到的ajax内容是否包含summernote编辑器。 因此,在ajax成功函数中初始化summernote不是一种选择。
正文:
<body>
<a href="modal.html" class="ajaxPopup">Open Summernote</a>
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">X</button>
<h4 class="modal-title">Modal title</h4>
</div>
<div class="modal-body">
<div class="te"></div>
</div>
</div>
</div>
</div>
<script type='text/javascript'>
var $myModal = null;
$(document).ready(function () {
$myModal = $('#myModal');
$('.ajaxPopup').on('click', function () {
$.ajax({
url: 'modal.html',
type: 'GET',
context: this,
success: function (response) {
$myModal.find('.modal-title').html("Summernote");
$myModal.find('.modal-body').html(response);
$myModal.modal({
show: true,
backdrop: true
});
}
});
return false;
});
});
</script>
</body>
modal.html内容
<div id='commentBox'></div>
<script type='text/javascript'>
$(function () {
$('#commentBox').summernote();
});
</script>
有什么建议吗?
答案 0 :(得分:1)
在打开之前清空模态正文内容可以解决此问题。
var $myModal = null;
$(document).ready(function () {
$myModal = $('#myModal');
$('.ajaxPopup').on('click', function () {
$myModal.find('.modal-body').html('');
$.ajax({
url: '/echo/html/',
data: {
html: "<div id='commentBox'></div>" + "<script type='text/javascript'>$(function () {$('#commentBox').summernote();});<\/script>"
},
type: 'POST',
context: this,
success: function (response) {
$myModal.find('.modal-title').html("Summernote");
$myModal.find('.modal-body').html(response);
$myModal.modal({
show: true,
backdrop: true
});
}
});
return false;
});
});