对不起,我的错误,但我很小白:DI必须设置分钟日期在HTML与IF输入:如果今天是> 2019年1月6日设定分钟到今天,否则设置min到2019年1月6日任何人可以帮我?这是我的代码:
function setMin1() {
var varData = new Date('01-06-2019'); //dd-mm-YYYY
var today = new Date();
today.setHours(0,0,0,0);
if(varData >= today) {
document.getElementById('set').min = '01-06-2019';
}
else {
document.getElementById('set').min = '<?php echo date('d-m-Y');?>';
}
}
它不会工作,因为你传递一个字符串输入。你输入类型号。您可以使用的数据类型来代替。
我想输入类型为date。可以使用min属性设定的最小值,例如
<input type="date" name="someDate" min="2019-01-01">
请注意,在HTML中,ISO 8601格式的日期将被视为地方,但是当通过内置的ECMAScript解析器解析将被视为UTC。
如果您在使用脚本设置的值,你依靠主机系统的时钟是准确的。该值可以通过使用setAttribute设置:
window.onload = function(){
var d = new Date();
// Build ISO 8601 format date string
var s = d.getFullYear() + '-' +
('0' + (d.getMonth()+1)).slice(-2) + '-' +
('0' + d.getDate()).slice(-2);
// Set the value of the value and min attributes
var node = document.querySelector('input');
if (node) {
node.setAttribute('min', s);
node.setAttribute('value', s);
}
}
<form onsubmit="return false;">
<input type="date"><br>
<input type="reset">
</form>
我知道你在寻找的是setAttribute方法:
document.getElementById('set').setAttribute('min', '01-06-2019');