尝试调用时,我收到错误消息“Uncaught TypeError: $(...).valid is not a function”
javascript
$('input[data-val=true]').on('blur', function() {
$(this).valid();
});
Run Code Online (Sandbox Code Playgroud)
HTML
<div class="col-xs-12 col-sm-5" style="margin-left:4px">
<input required="True" class="form-control" data-bind="value: battleModel.ReserveTroopCount" data-val="true" data-val-number="The field Troop reserve must be a number." data-val-range="Troop reserve must be between 0 and 1000." data-val-range-max="1000" data-val-range-min="0" data-val-required="Troop reserve is required." id="ReserveTroopCount" name="ReserveTroopCount" placeholder="Troop reserve..." tabindex="1" title="Enter the minimum troops you want to reserve after the battle" type="text" value="5">
<span class="field-validation-valid" data-valmsg-for="ReserveTroopCount" data-valmsg-replace="true"></span>
</div>
Run Code Online (Sandbox Code Playgroud)
参考
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="/Content/bootstrap.css" rel="stylesheet" …Run Code Online (Sandbox Code Playgroud)