簡體   English   中英

使用Parsley禁用輸入類型編號上的“步驟”驗證行為

[英]Disable 'step' validation behavior on input type number with Parsley

使用Parsley.js html5驗證時,可以對輸入類型編號禁用“逐步”驗證(不更改文本類型。。。)

<input type="number" step="100" min="0" />

如果我在此字段中輸入“ 51”,則驗證失敗,因為它不是100(步驟)的倍數。 如何禁用此默認行為?

 /* jQuery Optional Number Step Version: 1.0.0 Author: Arthur Shlain Repo: https://github.com/ArthurShlain/JQuery-Optional-Step Issues: https://github.com/ArthurShlain/JQuery-Optional-Step/issues */ (function ($) { $.fn.optionalNumberStep = function (step) { var $base = $(this); var $body = $('body'); $body.on("mouseenter mousemove", '[data-optional-step]', function () { $(this).attr("step", $(this).attr('data-optional-step')); }); $body.on("mouseleave blur", '[data-optional-step]', function () { $(this).removeAttr("step"); }); $body.on("keydown", '[data-optional-step]', function () { var key = event.which; switch (key) { case 38: // Key up. $(this).attr("step", step); break; case 40: // Key down. $(this).attr("step", step); break; default: $(this).removeAttr("step"); break; } }); if (step === 'unset') { $base.removeAttr('data-optional-step'); } if ($.isNumeric(step)) { $base.attr('data-optional-step', step); } } }(jQuery)); jQuery(function() { $('.optional-step-100').optionalNumberStep(100); }); 
 <link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet"/> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <form class="container mt-5"> <h1 class="h3">JQuery Optional Number Step</h1> <div class="form-group" style="max-width: 300px"> <label>Example</label> <input type="number" class="form-control optional-step-100" value="0"> <button type="submit" class="btn btn-primary mt-2">Submit</button> <small id="emailHelp" class="form-text text-muted">Dynamic step for this field is 100 <br>You can specify any numeric value on keyboard. <br>HTML5 step validation will not be applied.</small> </div> <a class="btn btn-dark btn-sm" href="https://github.com/ArthurShlain/JQuery-Optional-Step" target="_blank">View on GitHub</a> </form> 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM