[英]How do you change a html text after form submission?
我正在嘗試創建一個表單,並根據表單的輸入,我想給出一個結果。
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="design.css">
<title>Plan <B></B></title>
</head>
<body>
<h1>Plan B</h1>
<form onsubmit="return processInputs()">
<label for="tnumber">Team Number:</label>
<input type="text" id="tnumber" name="tnumber"><br><br>
<input type="submit" value="Submit">
</form>
<p>Results:</p>
<p id="results">something</p>
</body>
<script type="text/javascript">
//Processing Inputs
function processInputs(){
document.getElementById("results").innerHTML = "77%";
}
</script>
</html>
上面,我通過制作表單屬性從數據中獲取輸入。 當用戶提交表單時,我希望“id=results”(在這種情況下,它是“某物”)的文本發生變化。 所以現在,我希望該文本更改為“77%”。
但是,提交表單后,代碼似乎不起作用。 有沒有辦法修復這個代碼?
謝謝。
將return false
添加到processInputs()
函數
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <link rel="stylesheet" href="design.css"> <title>Plan <B></B></title> </head> <body> <h1>Plan B</h1> <form onsubmit="return processInputs()"> <label for="tnumber">Team Number:</label> <input type="text" id="tnumber" name="tnumber"><br><br> <input type="submit" value="Submit"> </form> <p>Results:</p> <p id="results">something</p> </body> <script type="text/javascript"> //Processing Inputs function processInputs(){ document.getElementById("results").innerHTML = "77%"; return false; } </script> </html>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.