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
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. Just try attaching an onchange
to get the value of startInput and set it as the min
of the end Input. Check this pen .
startInput.addEventListener("change", e => {
endEls[index].setAttribute("min", e.target.value);
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.