获取原始HTML并将其重新呈现为HTML

时间:2022-12-14 20:10:00

I'm creating a script to rewrite the local version of the ETrack system my college uses as it's horrific, and I have a bit of an issue with formatted text. You see, there's a div on this system with the class .visitFeedback, and in this Div it has loads of <p> tags. I want to move these paragraphs into a scrollable div due to the paragraphs overflowing normally. The only issue is, these paragraphs have HTML styling within them (<strong> etc.). I want to reserve this formatting and just add it into a scrollable Div. So far I've managed to move it over, but all the methods I've tried so far return stuff like [object HTMLParagraph] instead of the text I want. So far I've tried .get(), .html(), .text(), and a few others. Can you please help? The relevant stuff is below:

我正在创建一个脚本来重写我学院使用的ETrack系统的本地版本,因为它很可怕,而且格式化文本有点问题。你看,这个系统上有一个带有.visitFeedback类的div,在这个Div中它有很多

标签。由于段落正常溢出,我想将这些段落移动到可滚动的div中。唯一的问题是,这些段落中有HTML样式(等)。我想保留这种格式,只需将其添加到可滚动的Div中。到目前为止,我已经设法将其移除,但到目前为止我尝试过的所有方法都返回了[object HTMLParagraph]而不是我想要的文本。到目前为止,我已经尝试过.get(),. html(),. text()和其他几个。你能帮忙吗?相关内容如下:

var feedbackTxt;

    $('.visitFeedback p').each(function(){
        if ($(this).hasClass('info'))
        {

        }
        else
        {
            feedbackTxt += $(this).text();
            $(this).remove();
        }
    });

    $('.visitFeedback').append('<div style="overflow-y: scroll;">' + feedbackTxt + '</div>');

1 个解决方案

#1


4  

Why not add overflow-y: scroll to elements with the .visitFeedback class?

为什么不添加overflow-y:使用.visitFeedback类滚动到元素?

$('.visitFeedback').css('overflow-y', 'scroll');

#1


4  

Why not add overflow-y: scroll to elements with the .visitFeedback class?

为什么不添加overflow-y:使用.visitFeedback类滚动到元素?

$('.visitFeedback').css('overflow-y', 'scroll');