[英]Display FCKeditor input data in HTML format on same page, as user types?
[英]HTML: Automatically Display Given Input on the Same Page
我想問我們應該如何在 HTML 中編寫以自動顯示 Web 用戶在同一頁面上給出的輸入,而無需按鈕或單擊。
這是我從其他地方復制的示例:
<!DOCTYPE HTML>
<HTML>
<head>
</head>
<body>
<script type="text/javascript">
function changeThis(){
var formInput = document.getElementById('theInput').value;
document.getElementById('newText').innerHTML = formInput; }
</script>
<p>You wrote: <span id='newText'></span> </p>
<input type='text' id='theInput'>
<input type='button' onclick='changeThis()' value='See what you wrote'/>
</body>
</html>
我想在不使用任何按鈕、單擊或 Enter 選項卡的情況下獲得相同的效果。
換句話說,給出的輸入顯示在用戶在行框上放東西之后的“你寫的”旁邊。
請看下面的代碼。 只要您在輸入框中輸入,它將立即寫入文本:
<!DOCTYPE html>
<html>
<body>
Enter your name: <input type="text" id="fname" onkeyup="myFunction()">
<p id="rewrite"></p>
<script>
function myFunction() {
var x = document.getElementById("fname");
document.getElementById("rewrite").innerHTML=x.value;
}
</script>
</body>
</html>
請參閱下面的代碼片段以獲取解決方案:
let input = document.querySelector('#theInput'); input.addEventListener('input', () => { document.querySelector('#newText').innerHTML = input.value; })
<p>You wrote: <span id='newText'></span> </p> <input type='text' id='theInput'> <input type='button' value='See what you wrote'/>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.