jQuery表单检测,提交后检测与实时检测
XML/HTML Code
- <div class="example-block mb-4">
- <form action="" class="user-registration mb-3">
- <h6 class="title mb-2 mt-0">User registration</h6>
- <div class="form-group">
- <label>Login *</label>
- <input name="login" type="text" data-validation-length="min:3" class="form-control" required>
- </div>
- <div class="form-group">
- <label>Email *</label>
- <input name="email" type="email" class="form-control" required>
- </div>
- <div class="form-group">
- <label>Password *</label>
- <input name="password" type="password" class="form-control" required>
- </div>
- <div class="form-group">
- <label>Website</label>
- <input name="website" data-validation-type="url" class="form-control">
- </div>
- <div class="form-group">
- <label>Bio</label>
- <textarea name="bio" data-validation-length="min:10,max:150" data-validation-hint="Describe yourself" class="form-control"></textarea>
- </div>
- <div class="form-group">
- <label class="mb-0">I agree to the terms of service *</label>
- <input type="checkbox" data-validation-message="You have to agree to terms of service" required>
- </div>
- <div class="mb-2"><small>* required fields</small></div>
- <button type="submit" class="btn btn-primary">Submit</button>
- </form>
- </div>
JavaScript Code
- <script>
- $(document).ready(function() {
- /**
- * Initiate highlighting
- */
- hljs.initHighlightingOnLoad();
- /**
- * Initiate validation on each form.
- */
- $('.user-registration').validation({
- 'autocomplete': 'off',
- 'liveValidation': false
- });
- $('.live-validation').validation({
- 'autocomplete': 'off',
- 'liveValidation': true
- });
- });
- </script>
原文地址:http://www.freejs.net/article_biaodan_818.html