我的控制臺(tái)出現(xiàn)錯(cuò)誤:未捕獲的類(lèi)型錯(cuò)誤:$(...).offset() 未定義<div>在此之前,我使用 id創(chuàng)建了父級(jí)contentMessage,我從數(shù)據(jù)庫(kù)中獲取了所有數(shù)據(jù),并進(jìn)行了 jQuery 操作以在成功響應(yīng)中循環(huán)該數(shù)據(jù),我循環(huán)元素 a </div class"alert">,然后將其附加到我的父級(jí)中<div id="contentMessage">。當(dāng)我想自動(dòng)滾動(dòng)到附加的最新警報(bào)時(shí),出現(xiàn)錯(cuò)誤。//my append element into `<div id=contentMessage>`$.ajax({ url: "<?= $apiEndpoint ?>/message/", type: "GET", data: { outlet_from: outlet_from, outlet_to: outlet_to, from: id_from, to: id_to }, dataType: "JSON", success: function(res) { let a = 0 let resCount = res.length window.count = resCount -= 1 if (res.length == 0) { var append = $('<div/>', { "class": "parent_message p-2", }).append( $('<div/>', { 'class': 'text-center', text: 'Tidak Ada Pesan' }) ) $("#contentMessage").append(append) } $.each(res, function(key, val) { var d = new Date(res[a].created_at) if (d.getMinutes() < 10) { var times = d.getHours() + ":" + "0" + d.getMinutes() } else { var times = d.getHours() + ":" + d.getMinutes() } if (res[a].from === <?= $user_id ?>) { if (a == window.count) { window.message = $('<div/>', { "class": "alert alert-primary alert-dismissible alertFrom ", "id": "resMessage", text: res[a].message }).append($('<small/>', { text: times })) } else { window.message = $('<div/>', { "class": "alert alert-primary alert-dismissible alertFrom", text: res[a].message }).append($('<small/>', { text: times })) }這是我的滾動(dòng)代碼:window.setTimeout(function() { $('.contentMessage').animate({ scrollTop: $("#resMessage").offset().top }, 3000);}, 2000);
未捕獲的類(lèi)型錯(cuò)誤:當(dāng)我的目標(biāo)是追加元素時(shí),$(...).offset() 未定義
撒科打諢
2023-08-18 16:25:02