第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

未捕獲的類(lèi)型錯(cuò)誤:當(dāng)我的目標(biāo)是追加元素時(shí),$(...).offset() 未定義

未捕獲的類(lèi)型錯(cuò)誤:當(dāng)我的目標(biāo)是追加元素時(shí),$(...).offset() 未定義

撒科打諢 2023-08-18 16:25:02
我的控制臺(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);
查看完整描述

1 回答

?
斯蒂芬大帝

TA貢獻(xiàn)1827條經(jīng)驗(yàn) 獲得超8個(gè)贊

只需將“scrollfunction”放置在創(chuàng)建 id resMessage 的元素的代碼下方即可。否則(在您的示例中,如果 ajax 響應(yīng)和元素創(chuàng)建花費(fèi)的時(shí)間超過(guò) 2000 毫秒,則該元素將不存在,您將看到您描述的錯(cuò)誤)


success:function(res){


  ...


  window.setTimeout(function() {

    $('.contentMessage').animate({

      scrollTop: $("#resMessage").offset().top

    }, 3000);

  }, 2000);

}

可能不再需要超時(shí)了;)


查看完整回答
反對(duì) 回復(fù) 2023-08-18
  • 1 回答
  • 0 關(guān)注
  • 143 瀏覽
慕課專(zhuān)欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)