Using an HTML input type="date"
and a submit button. I would like to populate the variables day
, month
, and year
with the appropriate values from the date input.
<input type="date" id="date-input" required />
<button id="submit">Submit</button>
and the jQuery:
var day, month, year;
$('#submit').on('click', function(){
day = $('#date-input').getDate();
month = $('#date-input').getMonth() + 1;
year = $('#date-input').getFullYear();
alert(day, month, year);
});
Here's a code sample:
https://jsfiddle.net/dkxy46ha/
the console error is telling me that .getDate()
is not a function.
I have seen similar questions but the solutions have not worked for me. How can I extract the day, month and year from the input type="date"
? Thanks
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…