如果有两个按钮,请联系Field按钮

Contact the Field button when there are two buttons

本文关键字:按钮 联系 Field 两个 如果      更新时间:2023-09-26

我有个问题。我想建立一个包含两个字段的主页:用户名和密码,然后单击"确定"按钮。在该按钮下,有一个按钮单击Sign如何将现有用户按钮的字段与注册按钮相关联?

<fieldset>
    <legend>login details</legend>
        <div class="form-group ">
            <label for="username">user name:</label>
            <input type="text" name="username" class="form-control requiredField signIn" id="username">
        </div>
        <div class="form-group">
            <label for="password">password:</label>
            <input type="password" name="password" class="form-control requiredField signIn" id="password">
        </div>
        <div class="form-group">
            <button type="submit" class="btn btn-default butt" name="submitButton" value="signIn">OK</button>
        </div>  
    </fieldset>
    <fieldset>
    <legend>Sign in</legend>
        <div class="form-group">
            <label for="password">Account Number:</label>
            <input type="password" name="account" class="form-control requiredField regi" id="account">
        </div>
        <div class="form-group">
            <button type="submit" class="btn btn-default butt" name="submitButton" value="regi">Registration</button>
        </div>

$(document).ready(function){

//函数registration_submit(){

$("form").submit(function(){
    $(".error").remove();
    var hasError = false;
    if (Request.Form("submitButton":("signIn"){
    $(this).each(function(){
        if(jQuery.trim($(this).val()) == ''){
            hasError = true;
            var labelText = $(this).prev("label").text();
            var n = labelText.lastIndexOf(":");
            labelText = labelText.slice(0,n);
            $(this).parent().append('<span class="error"> you must fill ' + labelText + '</span>');
            console.log('the value of hasError is' + hasError);
            }
        });
    }
    else{
    $(".regi").each(function(){
        if(jQuery.trim($(this).val()) == ''){
            hasError = true;
            $(this).parent().append('<span class="error">you must fill Account Number</span>');
            console.log('the value of hasError is' + hasError);
        }           
    });
    }
    if(!hasError){
        $(this).submit();
    }
    return false;
});

});