首页 > 解决方案 > 根据 Laravel 中的另一个字段设置字段的最小值

问题描述

我的表单中有一个startstop字段,我希望用户输入一个start字段然后输入该stop字段,但是,该字段的最小值stop需要是该start字段的值。有什么办法可以做到这一点?

我的观点:

    <div class="mb-3" style="float:left;" style="margin-left: 200px;">
                    <label for="recipient-name" style="width: 7em"class="col-form-label">Start</label>
                    <input type="number"style="width: 7em" name="start" class="form-control" id="start" min="0" required>

 <div class="mb-3" style="float:left;" style="margin-left: 200px;">
                    <label for="recipient-name" style="width: 7em"class="col-form-label">Stop</label>
                    <input type="number"style="width: 7em" name="stop" class="form-control" id="stop" min="0" required>
              
              </div>

标签: laravellaravel-8laravel-blade

解决方案


使用这个简单的 jQuery 方法:

Add `disabled` attribute in your stop input Html

<input type="number"style="width: 7em" name="stop" class="form-control" 
disabled id="stop" min="0" required>

然后使用jQuery:

$(document).on('blur','#start',function(){
 //make stop input disabled false after focus out from start input
    $("#stop").prop("disabled",false);
//set stop input minimum value to start value
    $("#stop").attr("min",$("#start").val());
    $("#stop").val($("#start").val());
});

推荐阅读