我是 html 的初學者,我試圖學習 html 中的表單是如何作業的,但如下面的代碼所示,單擊提交按鈕后我無法獲得表單結果。你能告訴我為什么它不起作用以及如何解決它嗎?
索引.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>html/css</title>
</head>
<body>
<form action="result.html" method="get">
<label for="N">Name:</label>
<input type="text" id="N" name="Name" required>
<br>
<label for="P">Phone number:</label>
<input type="number" id="P" name="phone_nos" required>
<br>
<button>submit</button>
<br>
</form>
</body>
</html>
結果.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div id="results"></div>
<a href="/">Go Back</a>
<script>
const resultsList = document.getElementById('results')
new URLSearchParams(window.location.search).forEach(
(value,name)=>{ resultsList.append('${name} : ${value}')
resultsList.append(document.createElement('br'))
})
</script>
</body>
</html>
這是點擊提交按鈕后螢屏上顯示的內容
${name} : ${value} ${name} : ${value}
uj5u.com熱心網友回復:
嘗試將表單方法更改為 POST 而不是 get
--> <form action="result.html" method="post">
uj5u.com熱心網友回復:
<input>型別提交的元素呈現為按鈕。當單擊事件發生時(通常是因為用戶單擊了按鈕),用戶代理會嘗試將表單提交給服務器。
改變
<button>submit</button>
到
<input type="submit">
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/368415.html
標籤:javascript html
上一篇:如何為index.html以外的網頁運行/查看ExpressJS服務器?
下一篇:將物件轉換為物件陣列
