我有以下功能:jQuery的添加ID到正在附加到主体上的元件
simpleModal: function (data, id) {
var responseHtml = data;
// Append the modal HTML to the DOM
var modalInstance = $('body').append(modalHtml);
$(modalInstance).attr('id', id);
$(id).find('.uiModalContent').width(480);
$(id).find('.uiModalContent').height(320);
// Hide the modal straight away, center it, and then fade it in
$(id).find('.uiModal').hide().center().fadeIn();
// Dynamically load in the passed data from the call
$(id).find('.uiModalContent').html($(responseHtml));
$(id).find('.uiModalContent').removeClass('loading');
$(id).find('.ModalClose').live('click', function (e) {
e.preventDefault();
$(this).parents('.uiModal').fadeOut(function() { $(this).parents('.uiModalWrapper').remove() });
});
},
时调用,如:
uiModal.simpleModal('<p>An error has occured</p>','TestError');
应该模态追加到体与传递的内容,并给modalHtml一个ID也是通过。然而它会混淆添加id到body而不是html。我如何解决这个问题?谢谢
_modalInstance_是您的身体元素。那就是问题所在。 - '$(modalInstance).attr('id',id); // var modalInstance = $('body')...' – Smamatti