审查视图

public/assets/libs/nice-validator/demo/option-display.html 1.8 KB
郭盛 authored
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Display</title>
    <link rel="stylesheet" href="demo.css">

    <script src="https://cdn.jsdelivr.net/jquery/1.12.3/jquery.min.js"></script>
    <script src="../dist/jquery.validator.js?local=en"></script>
</head>

<body>

<form class="form" data-validator-option="{timely:2}">
    <h3>Default behavior</h3>
    <p class="note">data-rule="required"</p>
    <div class="form-item">
        <input type="text" name="name" data-rule="required">
    </div>
    <div class="form-item">
        <button type="submit">Submit</button>
    </div>
</form>

<form class="form" data-validator-option="{timely:2}">
    <h3>Set the field display by rule string</h3>
    <p class="note">data-rule="Name: required"</p>
    <div class="form-item">
        <input type="text" name="name" data-rule="Name:required">
    </div>
    <div class="form-item">
        <button type="submit">Submit</button>
    </div>
</form>

<form class="form" data-validator-option="{timely:2}">
    <h3>Set the field display by bind display</h3>
    <p class="note">data-rule="required" data-display="Name"</p>
    <div class="form-item">
        <input type="text" name="name" data-rule="required" data-display="Name">
    </div>
    <div class="form-item">
        <button type="submit">Submit</button>
    </div>
</form>

<form class="form" id="form4">
    <h3>Dynamic get field display.</h3>
    <div class="form-item">
        <label class="label">Name</label>
        <input type="text" name="name" data-rule="required">
    </div>
    <div class="form-item">
        <button type="submit">Submit</button>
    </div>
</form>
<script>
$('#form4').validator({
    timely:2,
    display: function(el) {
        return $(el).closest('.form-item').find('label.label').text();
    }
});
</script>


</body>
</html>