[英]get month and year from date input
我有以下 html 代码:
<input type="date" id="myDate"/>
<button type="button" class="btn btn-secondary" id="clickMe">MyButton</button>
我正在尝试在 js function 中使用日期输入(仅月份和年份)中的值,如下所示:
function myFunction() {
function function1(a,b)
{
//do something with a and b values
}
function function2()
{
var a = document.getElementById('myDate').value.month; //this values are not good
var b = document.getElementById('myDate').value.year;
function1(a,b)
}
var el = document.getElementById("clickMe");
if (el.addEventListener)
el.addEventListener("click", function2, false);
else if (el.attachEvent)
el.attachEvent('onclick', function2);
})();
基本上,当按下按钮时,我想将输入日期的值保存为 int 值(例如 7 和 2020 - 月份和年份),这些值将在 js 函数 2 中传输,该函数将使用这些参数调用函数 1。
问题是正确知道我的 a 和 b 变量是 null。 有什么办法可以解决这个问题吗?
我对这些值(a 和 b)进行了调试,但出现以下错误:“TypeError: 'caller', 'callee', and 'arguments' properties may not be access on strict mode functions or the arguments objects for calls to他们”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.