[英]JQuery Autofill with Keyup function
I would like to put in "max" and "min" values in separate input fields and then have another set of input fields autofill with all the integers in between and included the min and max #'s.我想在单独的输入字段中输入“最大”和“最小”值,然后让另一组输入字段自动填充其间的所有整数,并包括最小和最大#。 I've never used JS before so I'm not sure if there is a method for this or if you need to loop through the numbers?
我以前从未使用过 JS,所以我不确定是否有这种方法,或者您是否需要遍历数字?
$("#min1").keyup(function(){
$("#speed1").val(this.value);
});
$("#max1").keyup(function(){
$("#speed5").val(this.value);
});
Just add one event for the boths (use input
instead of keyup
it's more effecient when we want to track input field change) then call result()
function that will clear result div then generate input fields :只需为两者添加一个事件(使用
input
而不是keyup
当我们想要跟踪输入字段更改时它更有效)然后调用result()
函数,该函数将清除结果 div 然后生成输入字段:
function result(min,max){ $("#result").html(""); for(var i=min;i<=max;i++) $("#result").append('<input type="number" value="'+i+'"/>'); } $("body").on('input', '#min1,#max1', function(){ var min = $('#min1').val(); var max = $('#max1').val(); if( min!="" && max!="") if( min<max ) result(min, max); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <input id="min1" type="number" placeholder="min" value="0"/> <input id="max1" type="number" placeholder="max" value="0"/> <div id="result"></div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.