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

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Textarea scrollHeight 不更新防止自動調(diào)整大小

Textarea scrollHeight 不更新防止自動調(diào)整大小

撒科打諢 2022-07-21 20:51:29
我有點卡在看似簡單但行不通的事情上。我想在模式中創(chuàng)建一個自動調(diào)整大小的文本區(qū)域。textarea 的值根據(jù)激活模態(tài)的元素添加到模態(tài)顯示中。在模態(tài)外觀上,textarea 未調(diào)整大小,控制臺將 0 報告為 scrollHeight。如果我單擊文本區(qū)域,它會調(diào)整大小。如果我從文本區(qū)域輸入或刪除文本,它會調(diào)整大小。當(dāng)以編程方式設(shè)置值時,我無法弄清楚為什么它會報告 scrollHeight 0 。調(diào)整大小函數(shù)如下。$(document).on("input change focus", "textarea.notesarea", function (e) {    this.style.height = 'auto';    console.log(this.scrollHeight+ "-"+ $(this)[0].scrollHeight);     if (this.scrollHeight == 0) {        this.style.height = "calc(2.25rem + 2px)";    } else {        this.style.height = 0;        this.style.height = (this.scrollHeight + 4) + "px";    }});
查看完整描述

1 回答

?
長風(fēng)秋雁

TA貢獻1757條經(jīng)驗 獲得超7個贊

一個快速而骯臟的解決方案是強制代碼等到第一次打開模式后再添加“calc(2.25rem + 2px)”;到它的高度。您可以使用 setTimeout(function(){... 例如:


$(document).on("input change focus", "textarea.notesarea", function (e) {

    this.style.height = 'auto';

    console.log(this.scrollHeight+ "-"+ $(this)[0].scrollHeight); 

    if (this.scrollHeight == 0) {

        that = this;

        setTimeout(function(){

          that.style.height = "calc(2.25rem + 2px)";

        },300);

    } else {

        this.style.height = 0;

        this.style.height = (this.scrollHeight + 4) + "px";

    }

});


查看完整回答
反對 回復(fù) 2022-07-21
  • 1 回答
  • 0 關(guān)注
  • 304 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

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

公眾號

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