首页 > 解决方案 > html 字符串未在 textarea 字段中正确填充

问题描述

我需要能够在 textarea 中呈现一些 HTML 标签(即 , , , ),但 textareas 仅将其内容解释为文本。预期的字符串如下

<strong><span style=""background-color: yellow"">I AGREE </span>TO THE TERMS AND CONDITIONS OF THE CONSUMER INSTALLMENT LOAN AGREEMENT (this “Contract”).<br>By electronically signing the Contract by checking the box above and then clicking the “Get Loan Now” button below, you (i) acknowledge receipt of this Contract, with all necessary spaces filled in, (ii) certify you fully read and understand the Contract and you agree to comply with and be bound by its terms, and (iii) you reaffirm consent to the use of electronic records for all transactions with LendNation and all documents relating to those transactions.</strong>

但它替换为下面

\u003cstrong\u003e\u003cspan style\u003d\"background-color: yellow\"\u003eI AGREE \u003c/span\u003e "TO THE TERMS OF THE VOLUNTARY ACH CREDIT AUTHORIZATION AGREEMENT(the "ACH Credit Authorization")".\u003c/strong\u003e\u003cbr\u003e "By electronically signing the ACH Credit Authorization by checking the box above and then clicking the "Get Loan Now" button below, you certify you fully read and understand the ACH Credit Authorization provision of the Contract, and you agree to comply with and be bound by its terms."\u003cbr/\u003e"

标签: jqueryhtml

解决方案


这不能用 textarea 来完成,但看一下contenteditable属性。

<div contenteditable="true">
    This text can be edited by the <strong>user</strong>.
</div>

https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Editable_content


推荐阅读