admin管理员组文章数量:1426617
I'm trying to set the modal text after it's been launched by a jQuery click event, but I'm unsuccesful. Can somebody give me some pointers?
I have tried setting the title, body and button dynamically, but for some reason it's not added.
$(function() {
$(".contact-input-plus").on( "click", "a", function() {
if ( ! $(this).is(".remove")) {
// Do stuff
} else {
$('#confirm').modal('show');
$('#confirm').on('show.bs.modal', function() {
var modal = $(this);
modal.find('.modal-body p').text('You are about to remove this entry. Are you sure?');
modal.find('.modal-header h4').html('Remove entry');
modal.find('.modal-footer a.btn').text('Remove');
});
}
return false;
});
});
Note: I need to clarify something. The modal is displayed firstly without the text set. When I cancel and fire the modal again, the text is inserted.
I'm trying to set the modal text after it's been launched by a jQuery click event, but I'm unsuccesful. Can somebody give me some pointers?
I have tried setting the title, body and button dynamically, but for some reason it's not added.
$(function() {
$(".contact-input-plus").on( "click", "a", function() {
if ( ! $(this).is(".remove")) {
// Do stuff
} else {
$('#confirm').modal('show');
$('#confirm').on('show.bs.modal', function() {
var modal = $(this);
modal.find('.modal-body p').text('You are about to remove this entry. Are you sure?');
modal.find('.modal-header h4').html('Remove entry');
modal.find('.modal-footer a.btn').text('Remove');
});
}
return false;
});
});
Note: I need to clarify something. The modal is displayed firstly without the text set. When I cancel and fire the modal again, the text is inserted.
Share Improve this question edited Sep 6, 2015 at 21:01 Taapo asked Sep 6, 2015 at 20:48 TaapoTaapo 1,9974 gold badges20 silver badges36 bronze badges 4-
Is
$('#confirm').modal('show');
firing properly? Is! $(this).is(".remove")
evaluating the way you intend it to? – Tim Commented Sep 6, 2015 at 21:00 - Yes, it's firing properly. But the text values are not added to the modal the first time - only from the second time on ... – Taapo Commented Sep 6, 2015 at 21:02
- So opening the modal on the first attempt the text is not added, but on subsequent attempts it is? – Tim Commented Sep 6, 2015 at 21:03
- Exactly like you describe it, indeed. – Taapo Commented Sep 6, 2015 at 21:04
1 Answer
Reset to default 3Try setting the dynamic stuff before calling the .show() like this:
$(function() {
$(".contact-input-plus").on( "click", "a", function() {
if ( ! $(this).is(".remove")) {
// Do stuff
} else {
var modal = $('#confirm');
modal.find('.modal-body p').text('You are about to remove this entry. Are you sure?');
modal.find('.modal-header h4').html('Remove entry');
modal.find('.modal-footer a.btn').text('Remove');
$('#confirm').modal('show');
}
return false;
});
});
本文标签: javascriptSet Bootstrap Modal text dynamicallyStack Overflow
版权声明:本文标题:javascript - Set Bootstrap Modal text dynamically? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745479725a2660121.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论