我想从texarea获取原始文本,这是指不转换unicode值,例如:
let textArea=document.querySelector("textarea");
let value=textArea.value;
let valueSpan=document.querySelector(".value .text")
let valueinnerHTML=document.querySelector(".innerHTML .text");
console.log(value);
console.log(textArea.innerHTML);
valueSpan.textContent =value;
valueinnerHTML.textContent=textArea.innerHTML;
.wrapper{
display: grid;
grid-template-columns: 1fr;
grid-gap: 5px;
}
.test{
display: grid;
grid-template-columns: 1fr;
grid-gap: 3px;
}
<textarea class="hide">
Unicode: 🐤
Icon:
</textarea>
<div class="wrapper">
<div class="value test">
<h3> Value</h3>
<span class="text"></span>
</div>
<div class="innerHTML test">
<h3> InnerHTML</h3>
<span class="text"></span>
</div>
</div>
我想获取原始文本,所以当我获取文本区域值时,我得到的是“&#128036”而不是
答案 0 :(得分:2)
使用“”。codePointAt(0)
将返回“ 128036”。如果您想了解this,请查看。
let value=document.querySelector("textarea").value
let span=document.querySelector("span");
span.textContent =value.codePointAt(0);
<textarea class="hide">
</textarea>
<span></span>
答案 1 :(得分:1)
使用Unicode表示“&”以显示Unicode
&#1 2 8 0 3 6;显示&#1 2 8 0 3 6;
let textArea=document.querySelector("textarea");
let value=textArea.value;
let valueSpan=document.querySelector(".value .text")
let valueinnerHTML=document.querySelector(".innerHTML .text");
console.log(value);
console.log(textArea.innerHTML);
valueSpan.textContent =value;
valueinnerHTML.textContent=textArea.innerHTML;
.wrapper{
display: grid;
grid-template-columns: 1fr;
grid-gap: 5px;
}
.test{
display: grid;
grid-template-columns: 1fr;
grid-gap: 3px;
}
<textarea class="hide">
Unicode: &#128036;
Icon:
</textarea>
<div class="wrapper">
<div class="value test">
<h3> Value</h3>
<span class="text"></span>
</div>
<div class="innerHTML test">
<h3> InnerHTML</h3>
<span class="text"></span>
</div>
</div>
答案 2 :(得分:-1)
&#128036
使用Unicode表示&。