如何使用HTML的用户输入在JavaScript中制作确认页面

发布于 2025-01-22 16:06:41 字数 1159 浏览 2 评论 0原文

我正在尝试使用一个将用户输入存储在查询字符串中的脚本的HTML页面,然后在确认页面中使用适当的标签/说明显示给用户。这是我到目前为止的目标,我对JavaScript非常新,但对HTML有一定的经验。

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="utf-8" />
  <title>Bob's Pet Store</title>
  <script src="petshop.js"></script>
</head>

<body>
  <form id="myForm">
    <h1>Place your customer information below!</h1>
    <h2>Customer Information:</h2>
    <h3>Please enter the neccessary information.</h3>
    <p>First Name: <input type="text" id="fname" /></p>
    <p>Last Name: <input type="text" id="lname" /></p>
    <p>Email Address: <input type="text" id="address" /></p>
    <p>State: <input type="text" id="state" /></p>
    <p>Phone Number: <input type="text" id="number" /></p>
    <br></br>
    <br><input type="submit" id="submit" value="Submit Information"></form>
  </br>
</body>

</html>

I'm attempting to make an HTML page with a script that will store the user's input in a query string, then display it back to the user with the appropriate labels/descriptions in a confirmation page. This is what I have so far, I'm very new to Javascript but have some experience with HTML.

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="utf-8" />
  <title>Bob's Pet Store</title>
  <script src="petshop.js"></script>
</head>

<body>
  <form id="myForm">
    <h1>Place your customer information below!</h1>
    <h2>Customer Information:</h2>
    <h3>Please enter the neccessary information.</h3>
    <p>First Name: <input type="text" id="fname" /></p>
    <p>Last Name: <input type="text" id="lname" /></p>
    <p>Email Address: <input type="text" id="address" /></p>
    <p>State: <input type="text" id="state" /></p>
    <p>Phone Number: <input type="text" id="number" /></p>
    <br></br>
    <br><input type="submit" id="submit" value="Submit Information"></form>
  </br>
</body>

</html>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

落日海湾 2025-01-29 16:06:41

为此,您可以使用ID的确认()和.value来完成工作:

javascript:

    function buttonFunction() {

var confirmationFNAME = document.getElementById("fname").value
confirm("Is, " + confirmationFNAME + " the right information?")

var confirmationLNAME = document.getElementById("lname").value
confirm("Is, " + confirmationLNAME + " the right information?")

var confirmationADDRESS = document.getElementById("address").value
confirm("Is, " + confirmationADDRESS + " the right information?")

var confirmationSTATE = document.getElementById("state").value
confirm("Is, " + confirmationSTATE + " the right information?")

var confirmationNUMBER = document.getElementById("number").value
confirm("Is, " + confirmationNUMBER + " the right information?")

}

html(添加到按钮中):

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="utf-8" />
  <title>Bob's Pet Store</title>
  <script src="petshop.js"></script>
</head>

<body>
  <form id="myForm">
    <h1>Place your customer information below!</h1>
    <h2>Customer Information:</h2>
    <h3>Please enter the neccessary information.</h3>
    <p>First Name: <input type="text" id="fname" /></p>
    <p>Last Name: <input type="text" id="lname" /></p>
    <p>Email Address: <input type="text" id="address" /></p>
    <p>State: <input type="text" id="state" /></p>
    <p>Phone Number: <input type="text" id="number" /></p>
    <br></br>
    <br><input onclick = "buttonFunction()" type="submit" id="submit" value="Submit Information"></form>
  </br>
</body>

</html>

希望这有帮助,如果您有任何错误或问题,请随时接触或发表评论。

for this you could use confirm() and .value of the ID to get the job done like so:

JAVASCRIPT:

    function buttonFunction() {

var confirmationFNAME = document.getElementById("fname").value
confirm("Is, " + confirmationFNAME + " the right information?")

var confirmationLNAME = document.getElementById("lname").value
confirm("Is, " + confirmationLNAME + " the right information?")

var confirmationADDRESS = document.getElementById("address").value
confirm("Is, " + confirmationADDRESS + " the right information?")

var confirmationSTATE = document.getElementById("state").value
confirm("Is, " + confirmationSTATE + " the right information?")

var confirmationNUMBER = document.getElementById("number").value
confirm("Is, " + confirmationNUMBER + " the right information?")

}

HTML (added onclick to button):

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="utf-8" />
  <title>Bob's Pet Store</title>
  <script src="petshop.js"></script>
</head>

<body>
  <form id="myForm">
    <h1>Place your customer information below!</h1>
    <h2>Customer Information:</h2>
    <h3>Please enter the neccessary information.</h3>
    <p>First Name: <input type="text" id="fname" /></p>
    <p>Last Name: <input type="text" id="lname" /></p>
    <p>Email Address: <input type="text" id="address" /></p>
    <p>State: <input type="text" id="state" /></p>
    <p>Phone Number: <input type="text" id="number" /></p>
    <br></br>
    <br><input onclick = "buttonFunction()" type="submit" id="submit" value="Submit Information"></form>
  </br>
</body>

</html>

Hope this helped, if you got any bugs or problems feel free to reach out or comment.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文