所以我正在检查一个可以输入文本的网站字段。在大多数文本框/字段中,当您输入文本时,它将保存为“innerText”或值“text”,但此字段不会在html中的任何位置保存字符串。这意味着我无法编辑该字段中的文本。
这个字符串存储在哪里,我怎么能用javascript编辑它?
<div id="mirror" class="mirror-text style-scope iron-autogrow-textarea" aria-hidden="false">sdslll </div>
<div class="textarea-container fit style-scope iron-autogrow-textarea">
<textarea id="textarea" class="style-scope iron-autogrow-textarea" rows="3" autocomplete="off" required="" maxlength="10000"></textarea>
</div>
如您所见,“镜像”包含我要编辑的文本。但是当我编辑它时,它不会生效
答案 0 :(得分:0)
<html>
<body>
<input id='in' type='text' />
<h3 id='out'></h3>
<script>
let input = document.getElementById('in');
let output = document.getElementById('out');
document.onkeyup = function () {
output.innerHTML = input.value;
};
</script>
</body>
</html>
答案 1 :(得分:0)
<script>
window.onload = function () { setValue(); }
function setValue(){
document.getElementById("mirror").value = "Some value here";
}
</script>
<input id="mirror" class="mirror-text style-scope iron-autogrow-textarea" aria-hidden="false" value="sdslll ">
<div class="textarea-container fit style-scope iron-autogrow-textarea">
<textarea id="textarea" class="style-scope iron-autogrow-textarea" rows="3" autocomplete="off" required="" maxlength="10000"></textarea>
</div>