禁用'继续'按键

时间:2016-04-07 17:49:46

标签: javascript jquery html css html5

所以我有以下字段,基本上是为了创建一个帐户。这只是一个原型。我想知道如何禁用继续按钮,只在所有字段完成后启用按钮。我已经看到这可以使用jQuery和表单来完成,但由于这不是一种形式,它不能正常工作。我知道它可能更容易使用,但我必须使用它们显示的所有字段。所以基本上有一种方法可以使用我已经拥有的东西吗?

 <div id="form1">

           <div class="row form-row form-bg">
    <div class="container">
        <div class="col-md-12 form-wrapper">
            <form role="form">
                <div class="form-content">

                        <legend class="hd-default">Account     information</legend>


                                <div class="row">
                                    <div class="form-group col-md-4 col-sm-6">
                                        <label for="first-name">Username*:  </label> 
                                        <input type="text" id="username" class="form-control" placeholder="Username" required="">
                                    </div>
                                </div>

                                <div class="row">
                                    <div class="form-group col-md-4 col-sm-6">
                                        <label for="password">Password*:</label><img src="help_icon.gif" title="Password must be between 8 and 15 characters, contain at least one number and one alphabetic character, and must not contain special characters." alt="Password must be between 8 and 15 characters, contain at least one number and one alphabetic character, and must not contain special characters.">
                                        <input type="text" id="password" class="form-control" placeholder="Password" required="">
                                    </div>
                                </div>

                                   <div class="row">
                                    <div class="form-group col-md-4 col-sm-6">
                                        <label for="password">Re-enter Password*:</label>
                                        <input type="text" id="password1" class="form-control" placeholder="Password" required="">
                                    </div>
                                </div>



                                </div>

                                <div id="form2">


                                  <div class="row form-row form-bg">
    <div class="container">
        <div class="col-md-12 form-wrapper">
            <form role="form">
                <div class="form-content">

                        <legend class="hd-default">Contact information</legend>

  <div class="row">
                            <div class="col-md-12">
                                <div class="row">
                                    <div class="form-group col-md-3 col-sm-3">
                                            <label>Title</label>
                                             <select name="title" class="form-control">
                                                  <option value="1">Mr</option>
                                                  <option value="2">Mrs</option>
                                                 <option value="3">Miss</option>
                                                   <option value="4">Dr</option>
                                                  <option value="5">Ms</option>
                                        </select>

                                    </div>


                                </div>
                                </div>
                                 <div class="row">
                                    <div class="form-group col-md-4 col-sm-6">
                                        <label for="first-name">First Names(s)*:</label> 
                                        <input type="text" id="firstname" class="form-control" placeholder="First Name(s)" required="">
                                    </div>
                                </div>

                                <div class="row">
                                    <div class="form-group col-md-4 col-sm-6">
                                        <label for="password">Surname*:</label> 
                                        <input type="text" id="surname" class="form-control" placeholder="Surname" required="">
                                    </div>
                                </div>

                                   <div class="row">
                                    <div class="form-group col-md-4 col-sm-6">
                                        <label for="password">Email*:</label>
                                        <input type="text" id="email" class="form-control" placeholder="Email" required="">
                                    </div>
                                </div>
                          <div class="row">
                                    <div class="form-group col-md-4 col-sm-6">
                                        <label for="password">Re-enter Email*:</label>
                                        <input type="text" id="email1" class="form-control" placeholder="Email" required="">
                                    </div>
                                </div>


                                </div>
                                </div>
                                </div>
                                </div>


                                </div>
  <div id="form3"
                               <form action="?" method="POST">
  <div class="g-recaptcha" data-sitekey="your_site_key"></div>
  <br/>

  </form>
                               </div>
                               <input type="submit" id="continue" value="Continue" disabled="disabled" a href="address.html"/>
                            </div>

                        </div>
                    </fieldset>
                </div>
            </form>
            </div>

1 个答案:

答案 0 :(得分:1)

您可能没有嵌套表单。

修复后,您可以在输入更改后检查字段是否为空。

$('#continue').click(function(e){
    e.preventDefault();
    if(checkFields())
        $('#form1').find('form').submit();
    return false;
});

function checkFields() {
    $('#form1 input').each(function(){
        if($(this).val() == '')
            return false;
        else
            return true;
    });
}