简体   繁体   English

将文本提交到文本框HTML中后,如何在上方显示文本

[英]How do I display text above after submitting it into a textbox HTML

I'm trying to create an area in which you can enter text into a text box and display the written text onto a box above in HTML. 我正在尝试创建一个区域,您可以在其中向文本框中输入文本,并将书面文本显示在HTML上方的框中。 I'm very new to HTML so any help will be greatly appreciated. 我是HTML的新手,因此将不胜感激。 I drew a beautiful picture of what I'm trying to make. 我画了一张我想做的美丽图画。 在此处输入图片说明

The best way to deal with this situation is use Javascript or jQuery which is javascript's library itself. 解决这种情况的最佳方法是使用Javascript或jQuery,这本身就是javascript的库。 Let me show you how you should do it in jQuery 让我向您展示如何在jQuery中进行操作

 <script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script> <script> $(document).ready(function(){ $("#form-to-be-submitted").click(function(){ $(".whatever-styling-you-want").html($("#textBox").val()); }); }); </script> <div class="whatever-styling-you-want"> </div> <!-- Your text box and submit button --> <div> <input type="text" id="textBox" placeholder="Please input your text here..."/> <input id="form-to-be-submitted" value="submit" type="button"/> </div> 

Javascript's way is also the same. JavaScript的方式也相同。 No need to use the click function but use javascript's on function with the 'click' event. 无需使用click函数,而是将JavaScript的on函数与'click'事件一起使用。 I hope this helps. 我希望这有帮助。

<!DOCTYPE HTML>
<html>
<head>
<style>

</style>
</head>
<body>
<p id="x"></p><br>
<input id="value"><input type="button" value="submit" onClick="getV()">
<script>
function getV(){document.getElementById("x").innerHTML = document.getElementById("value").value;}
</script>
</html>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM