简体   繁体   English

如何使用“signup.js”等外部脚本检查两个字段的身份?

[英]How do I check two fields for identity using an external script like "signup.js"?

I work with Electron.我与电子合作。 I have three files in my project.我的项目中有三个文件。

index.html索引.html

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <link rel="stylesheet" href="../css/styles.css">
        <script src="../js/preload.js"></script>
        <script src="../js/signup.js"></script>
    </head>
    <body>
        <form action="" onsubmit="return validate()">
            <label for="email"><b>Почта</b></label>
            <input type="text" placeholder="Введите почту..." name="email" required>
            <label for="psw"><b>Пароль</b></label>
            <input type="password" placeholder="Введите пароль..." id="psw" required>
            <label for="psw-repeat"><b>Подтверждение пароля</b></label>
            <input type="password" placeholder="Повторите пароль..." id="psw-repeat" required>
            <hr>
            <p id = "terms">Создавая аккаунт, вы соглашаетесь с нашими <a href="#">условиями пользования и приватности</a>.</p>
            <button type="submit" class = registerbtn>Зарегистрироваться</button>
        </form>      
    </body>
</html>

styles.css样式文件

@import url('https://fonts.googleapis.com/css2?family=Comfortaa:wght@300&display=swap');
@import url('https://fonts.googleapis.com/css2?family=Raleway&display=swap');

body {
    font-family: 'Raleway', sans-serif;
}

.sign_up {
    padding: 16px;
}

input[type=text],
input[type=password] {
    width: 100%;
    padding: 15px;
    margin: 5px 0 22px 0;
    display: inline-block;
    border: none;
    background: #f1f1f1;
    font-family: 'Raleway', sans-serif;
}

hr 
{
    border: 1px solid #f1f1f1;
    margin-bottom: 25px;
}

.registerbtn {
    background-color: darkcyan;
    color: white;
    padding: 16px 20px;
    margin: 8px 0;
    border: none;
    cursor: pointer;
    width: 100%;
    opacity: 0.9;
}

.registerbtn:hover {
    opacity: 1;
}

a {
    color: dodgerblue;
}

#warning {
    color: crimson;  
}

signup.js注册.js

function validate()
{
    var password = document.getElementById(psw).value;
    var password_repeat = document.getElementById(psw-repeat).value
    if(password != password_repeat)
    {
       document.getElementById(psw).insertAdjacentHTML("afterend", "<p id = \"warning\">Пароли не совпадают!</p>")
    }
}

The project itself is written in Russian.该项目本身是用俄语编写的。 I want to use the file signup.js to check the identity of the fields "psw" and "psw-repeat", but when the program runs, nothing happens.我想使用文件 signup.js 来检查字段“psw”和“psw-repeat”的身份,但是当程序运行时,没有任何反应。 As for the content of the fields, they are emptied when the button is clicked.至于字段的内容,当点击按钮时它们会被清空。

The onsubmit value should only have method call, not with "return". onsubmit值应该只有方法调用,而不是“返回”。

So, I suggest you to use something like this:所以,我建议你使用这样的东西:

onsubmit="validate()"

Documentation文档

Also, the submit button have issue with "class" css, it should look like this:此外,提交按钮有“类”css 问题,它应该是这样的:

<button type="submit" class="register btn">Зарегистрироваться</button>

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

相关问题 Drupal 7:如何在使用 drupal_add_js 时将 async 属性添加到外部 JS 脚本? - Drupal 7: how do I add the async attribute to an external JS script when using drupal_add_js? 如何进行注册脚本检查以进行付款验证 - How can I make my signup script check for payment validation 使用JQuery如何检查仅需要填写的两个字段 - Using JQuery how do I check two fields that I need one filled only React-native - SyntaxError: ..\src\screens\SignUp.js: Unexpected token, 应为“;” - React-native - SyntaxError: ..\src\screens\SignUp.js: Unexpected token, expected “;” 如何使用我添加的外部脚本来反应 JS? - How do I use external script that I add to react JS? 如何从 Protractor 加载/运行 external.js 脚本 - How do i load/run an external .js script from Protractor 如何在登录和注册社交之间做出不同的誓言流程? 像谷歌 oauth2.0 使用护照 js - How can i make a different oath flow between login & signup for social? like google oauth2.0 using passport js 如何使用LinkedIn集成注册/登录 - How do I integrate the signup/ signin using LinkedIn Express.js两条路径,例如在单个模块中进行注册和登录 - Express.js two routes like signup and signin in single module 如何在外部js中移动诸如“ ddaccordion.init”之类的jquery脚本? - How move a jquery script like “ddaccordion.init” in an external js?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM