appendChild 不是使用 $.confirm() 的函数

appendChild is not a function using $.confirm()

美好的一天,我正在努力解决这个问题。我花了 1 天时间尝试解决这个问题,但没有成功。

我正在尝试在 $.confirm() 上的 onContentReady 函数中附加一个 child,但似乎对我不起作用。这是代码

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。

我该怎么办?请帮忙

我猜你的选择器在 this.$content.find('confirm_body') 中不正确,如果 confirm_bodyid 元素然后使用 #,比如

...
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
}
...

body 是一个 jQuery 对象,而不是 DOM 对象,所以你应该使用

body.append($(h3));

最好也保持一致,坚持使用所有 jQuery 方法,而不是混淆原生 DOM 元素和 jQuery 对象。