我是Javascript的新手,但基本上我想要获取用户文本,一旦他们点击按钮,就可以将其输出到按钮下方。这就是我到目前为止所做的:
<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>
&#13;
答案 0 :(得分:0)
这没有jQuery。
在您的按钮中添加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>
答案 1 :(得分:0)
$("#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>