为什么输入类型 "date" 值不更新输入的新值
Why is the input type "date" value not updating new values from the input
我试图从输入类型“date”中获取日期,但是当我在 JavaScript 中检索数据时,始终只检索我设置的默认值。
无论我做什么,我总是得到默认值而不是我选择的新值。
I couldn't find any solution from all the similar questions about this, please do not flag this question because I am already getting a warning that my last question was not well received by the community, I thought we are here to learn and asking stupid questions is part of it.
var getInput = document.querySelector("#year");
var data = getInput.value, dob = data.split("-"), byy = dob[0], bmm = dob[1], bdd = dob[2];
function process(){
console.log(byy)
}
<input id="year" type="date" value="2022-12-25" required><br>
<input id="goBtn" onclick="process()" type="button" value="Go">
在您调用的函数中获取日期值。
function process() {
var getInput = document.querySelector("#year");
var data = getInput.value, dob = data.split("-"), byy = dob[0], bmm = dob[1], bdd = dob[2];
console.log(byy);
}
<input id="year" type="date" value="2022-12-25" required><br>
<input id="goBtn" onclick="process()" type="button" value="Go">
变量在 JavaScript 执行时立即被赋值,并赋予它们默认值。需要在您按下“开始”按钮时分配给它们。
我试图从输入类型“date”中获取日期,但是当我在 JavaScript 中检索数据时,始终只检索我设置的默认值。
无论我做什么,我总是得到默认值而不是我选择的新值。
I couldn't find any solution from all the similar questions about this, please do not flag this question because I am already getting a warning that my last question was not well received by the community, I thought we are here to learn and asking stupid questions is part of it.
var getInput = document.querySelector("#year");
var data = getInput.value, dob = data.split("-"), byy = dob[0], bmm = dob[1], bdd = dob[2];
function process(){
console.log(byy)
}
<input id="year" type="date" value="2022-12-25" required><br>
<input id="goBtn" onclick="process()" type="button" value="Go">
在您调用的函数中获取日期值。
function process() {
var getInput = document.querySelector("#year");
var data = getInput.value, dob = data.split("-"), byy = dob[0], bmm = dob[1], bdd = dob[2];
console.log(byy);
}
<input id="year" type="date" value="2022-12-25" required><br>
<input id="goBtn" onclick="process()" type="button" value="Go">
变量在 JavaScript 执行时立即被赋值,并赋予它们默认值。需要在您按下“开始”按钮时分配给它们。