繁体   English   中英

最小输入值取决于第二个输入

[英]The minimum input value depends on the second input

我尝试根据第二个值输入最小值。

desc:如果开始字段是12:00,那么结束字段不能输入小于12:00

我试过:

 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>

我相信你.start的开始输入和类.end类端输入。 只需尝试附加一个onchange来获取 startInput 的值并将其设置为结束 Input 的min 检查这支

startInput.addEventListener("change", e => {
    endEls[index].setAttribute("min", e.target.value);
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM