美好的一天,我正在努力解决这个问题。我花了 1 天的时间尝试解决这个问题,但没有成功。
我试图在 $.confirm() 的 onContentReady 函数中附加一个子项,但似乎对我不起作用。这是代码
html
<button onclick="btnclick()">click</button>
Javascript
function btnclick() {
// body...
$.confirm({
title:'test',
content: '<div class=".confirm_body"> </div>',
onContentReady:function() {
var body = this.$content.find('.confirm_body');
var h3 = document.createElement('h3');
h3.appendChild(document.createTextNode("child"));
body.appendChild(h3);
}
});
}
异常
jquery.min.js:2 jQuery.Deferred exception: body.appendChild is not a function TypeError: body.appendChild is not a function
at Jconfirm.onContentReady (http://localhost/NMSCST_CLINIC_INFORMATION_SYSTEM/:154:8)
at Array.<anonymous> (http://localhost/NMSCST_CLINIC_INFORMATION_SYSTEM/assets/jquery-confirm-v3.3.0/jquery-confirm.min.js:10:6129)
at j (http://localhost/NMSCST_CLINIC_INFORMATION_SYSTEM/assets/vendor/jquery/jquery.min.js:2:29568)
at k (http://localhost/NMSCST_CLINIC_INFORMATION_SYSTEM/assets/vendor/jquery/jquery.min.js:2:29882) undefined
r.Deferred.exceptionHook @ jquery.min.js:2
我的代码不显示 child 。
我该怎么办?请帮忙
最佳答案
如果 confirm_body
是元素的 id
,我猜您的选择器在 this.$content.find('confirm_body')
中不正确然后使用 #
,例如,
...
onContentReady:function() {
var body = this.$content.find('.confirm_body');
var h3 = document.createElement('h3');
h3.appendChild(document.createTextNode("child"));
body.append($(h3)); //make jQuery object for h3 element node & use append
}
...
关于javascript - appendChild 不是使用 $.confirm() 的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49123079/