[英]How to input user data through a text field, then display immediately below the text field?
I am new to Javascript, but basically I want to take the users text, and once they hit the button, be able to output it below the button. 我是Java语言的新手,但基本上我想带给用户文本,一旦他们按下按钮,就可以将其输出到按钮下方。 This is what I have so far:
这是我到目前为止的内容:
<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>
This is without jQuery. 这是没有jQuery的。
Add an id
to your button and create the empty text area with id 'textDiv'
and try this. 向您的按钮添加一个
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>
Result: http://jsfiddle.net/YoshiMaster/1r177khr/4/ 结果: http : //jsfiddle.net/YoshiMaster/1r177khr/4/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.