[英]The minimum input value depends on the second input
I try to enter a minimum value depending on the second value.我尝试根据第二个值输入最小值。
desc: if the start field is 12:00, then the end field cannot enter less than 12:00 desc:如果开始字段是12:00,那么结束字段不能输入小于12:00
I tried:我试过:
const ends = [...tr.querySelectorAll('.end')]; const getMin = timeStr => { const [hour, min] = timeStr.split(':'); return +hour * 60 + +min; }; [...tr.querySelectorAll('.start')] .forEach((el, i) => { el.addEventListener('change', e => { const value = e.target.value; const end = ends[i]; end.setAttribute('min', value); if (!end.value || getMin(end.value) < getMin(value)) { end.value = value; } }); });
<table> <tr> <td class="InputsForUserColor1"> <input class="start" type="time" id="id_start_1" /> </td> <td class="InputsForUserColor2"> <input class="end" type="time" id="id_end_1" max="23:59" /> </td> </tr> </table>
I believe you have .start
class for start Input and .end
class for end Input.我相信你
.start
的开始输入和类.end
类端输入。 Just try attaching an onchange
to get the value of startInput and set it as the min
of the end Input.只需尝试附加一个
onchange
来获取 startInput 的值并将其设置为结束 Input 的min
。 Check this pen .检查这支笔。
startInput.addEventListener("change", e => {
endEls[index].setAttribute("min", e.target.value);
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.