[英]How to input user data through a text field, then display immediately below the text field?
我是Java語言的新手,但基本上我想帶給用戶文本,一旦他們按下按鈕,就可以將其輸出到按鈕下方。 這是我到目前為止的內容:
<html lang="en"> <head> <meta charset="utf-8" /> <title>title</title> <link rel="stylesheet" href="main.css"> <script> var message = "#"; $("#message").text(message); </script> </head> <body> <div id="wrapper"> <var id="message"></var><textarea rows="4" cols="50" placeholder="Enter their post here, exactly word for word." id="post"></textarea></var> <button type="button">Submit</button> </div> </div> </body> </html>
這是沒有jQuery的。
向您的按鈕添加一個id
,並創建一個id
為'textDiv'
的空白文本區域,然后嘗試執行此操作。
<script type="text/javascript">
var button = document.getElementById('button_ID');
button.addEventListener('click',showText);
function showText() {
document.getElementById('textDiv').innerHTML = 'new text';
}
</script>
$("#button").click(function(){
var text = document.getElementById("post").value;
$("#message").html(text);
});
<div id="wrapper">
<textarea rows="4" cols="50" placeholder="Enter their post here, exactly word for word." id="post"></textarea>
<button id="button" type="button">Submit</button>
</div>
<span id="message"></span>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.