[英]How to change max or min value of input type date from JS
我有两个输入类型日期,例如:
<input type="date" name="first_date">
和其他类似:
<input type="date" name="second_date" min="first_date">
now what I want to do is that when first_date
is selected than the minimum range of the second_date
is auto filled by javascript.
任何想法如何做到这一点。
使用 onchange 事件设置属性的基本 JavaScript。
document.getElementById("firstDateId").onchange = function () {
var input = document.getElementById("secondDateId");
input.setAttribute("min", this.value);
}
使用 addEventListener 可以更好地编写代码。
我同意 epascarello 的回答,只有你可以用简单的.min
或.max
替换setAttribut("min/max")
。
document.getElementById("firstDateId").onchange = function ()
{
var input = document.getElementById("secondDateId");
input.min = this.value;
}
您应该能够在元素上使用 JavaScript 的.setAttribute('min',date)
。 详情请咨询W3C 。 如果您想使用库.attr('min',date)
还有 jQuery 的.attr('min',date)
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.