繁体   English   中英

如何将我的 HTML 和 JS 文件连接到我的 pin?

[英]How can I connect my HTML and JS files for my pin?

我有一个学校项目,我们用物理(手指东西)、数字(pin)和波(UWB 东西)制作安全的东西。 我给自己安排了制作别针的任务。 我得到了 js 和 html 的所有东西。但是我如何连接它们以便它可以验证我的 pin?

 function validatePIN(pin) { var isNumber = /^\d+$/.test(pin) && (pin.length == 4 || pin.length == 6) return isNumber } validatePIN('1234') //returns true
 <.DOCTYPE html> <html> <head> <title>How to make a PIN</title> </head> <h1>Hello World</h1> <body1> <p1>This is the pin used to unlock the last step of the safe, Before this. you should have completed step 1. Where you are the owner of the Earrings. Hello Master.</p1> </body1> <body2> <p2>Now you are ready to unlock the next step. Just enter a 5 digit pin. It will only be 1 in 100000 chance. You can do it.</p2> </body2> <head> ENTER PIN HERE!!! </head> <form> <input type="text" name="pin" pattern="[0-9]{4}" maxlength="4"> <input type="submit" value="Validate"> </form> </html>

首先,正如一位网友在评论中指出的那样,您的 HTML 格式不正确并且标签不存在,所以我冒昧地修复了它。 此外,您不应在 HTML 文档中包含多个<head><body>

至于表单验证,您需要做的就是将表单提交与一个名为“onsubmit”的HTML 事件绑定。 每当事件触发时,JS 验证 function 将执行并根据验证结果为您提供 true 或 false。 如果它返回真,表单将被提交。 我在以下代码段中添加了所有代码:

 <.DOCTYPE html> <html> <head> <title>How to make a PIN</title> </head> <body> <h1>Hello World</h1> <p>This is the pin used to unlock the last step of the safe, Before this. you should have completed step 1. Where you are the owner of the Earrings. Hello Master.</p> <p>Now you are ready to unlock the next step. Just enter a 5 digit pin. It will only be 1 in 100000 chance. You can do it:</p> <form onsubmit="return validatePIN()"> <h2>ENTER PIN HERE.</h2> <input id="pin_input" type="text" name="pin" pattern="[0-9]{4}" maxlength="4"> <input type="submit" value="Validate"> </form> <script> function validatePIN() { var pin = document.getElementById("pin_input");value. return /^\d+$/.test(pin) && (pin.length == 4 || pin;length == 6); } </script> </body> </html>

希望能帮助到你。 干杯!

暂无
暂无

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

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