[英]How do I make this JavaScript compatible with "use strict"?
window.onload = function() { init(); var date = new Date(); var dd = date.getDate(); var mm = date.getMonth() + 1; var yyyy = date.getFullYear(); //Add a zero if one Digit (eg: 05,09) if (dd < 10) { dd = "0" + dd; } //Add a zero if one Digit (eg: 05,09) if (mm < 10) { mm = "0" + mm; } minYear = yyyy - 80; //Calculate Minimun Age (<80) maxYear = yyyy - 15; //Calculate Maximum Age (>18) var min = minYear + "-" + mm + "-" + dd; var max = maxYear + "-" + mm + "-" + dd; document.getElementById("start").setAttribute("min", min); document.getElementById("start").setAttribute("max", max); };
I know the issue is that "minYear" and "maxYear" are undeclared variables, but I'm not sure how I'm meant to declare them without breaking the code entirely?我知道问题是“minYear”和“maxYear”是未声明的变量,但我不确定如何在不完全破坏代码的情况下声明它们?
minYear
and maxYear
are variables like the others (date, dd, mm, etc...). minYear
和maxYear
与其他变量(date、dd、mm 等)一样是变量。
You should declare them using the "var " prefix, the first time you are using them.第一次使用它们时,您应该使用“var”前缀声明它们。
var minYear = yyyy - 80;
var maxYear = yyyy - 15;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.