简体   繁体   中英

TEXTAREA assign html content to value — Not show html tag

I have the html file content and want to assign it to the TEXTAREA value. But how to not show html tag??

<TEXTAREA id="Terms"></TEXTAREA>
<script>
$.get("/mobile/en/html/tnc/apply.html", function(tnc) {
   var elem3 = document.getElementById('Terms');
   if (elem3){ elem3.value = tnc; }
});
</script>

apply.html

<html>
.......
</html>

As it has below function:

function disableDeclarationCheckbox() {
                var form = document.forms['CardForm'];
                var ta = document.getElementById('Terms');
                if (ta!=null && ta.scrollHeight <= ta.offsetHeight){
                    if (form){ if (form.cardTermsCheckbox){
                        form.cardTermsCheckbox.checked = false;
                        form.cardTermsCheckbox.disabled = false;
                    }}
                    return;
                }
                if (form){ if (form.cardTermsCheckbox){
                    form.cardTermsCheckbox.checked = false;
                    form.cardTermsCheckbox.disabled = true;
                }}
                $('textarea#Terms').on('scroll', function() {
                    if (this.scrollHeight <= (this.scrollTop+this.offsetHeight)) {
                        if (form){ if (form.cardTermsCheckbox){
                            form.cardTermsCheckbox.disabled = false;
                        }}
                    }
                });
                return;
            }

Text areas just show text, they don't interpret HTML.

Instead of a text area, use a div, like this:

<div id="Terms"></div>
<script>
$.get("/mobile/en/html/tnc/apply.html", function(tnc) {
   var elem3 = document.getElementById('Terms');
   if (elem3){ elem3.innerHTML = tnc; }
});
</script>

If you need users to be able to type into the div, you could change it to

<div id="Terms" contenteditable="true"></div>

使用<span>代替<textarea>

<span id='Terms'></span>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM