簡體   English   中英

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

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

我正在嘗試創建一個區域,您可以在其中向文本框中輸入文本,並將書面文本顯示在HTML上方的框中。 我是HTML的新手,因此將不勝感激。 我畫了一張我想做的美麗圖畫。 在此處輸入圖片說明

解決這種情況的最佳方法是使用Javascript或jQuery,這本身就是javascript的庫。 讓我向您展示如何在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的方式也相同。 無需使用click函數,而是將JavaScript的on函數與'click'事件一起使用。 我希望這有幫助。

<!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