Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
127 views
in Technique[技术] by (71.8m points)

javascript - Listening to onChange on a jQuery datepicker?

I currently am creating a date picker like so

HTML

<script src="https://code.jquery.com/ui/1.11.4/jquery-ui.min.js"></script>
<input id="datepicker" type="datepicker" name="date" placeholder="Date" />

JS

$('#datepicker').datepicker()
    .on("change", function (e) {
    console.log("Date changed: ", e.target.value);
});

My goal is to be able to listen for when the user clears out the date box. However, the change event only seems to fire once you unfocus the date box. I'm wondering if there's a way to listen for all changes in a jQuery date box, or if there are any better alternatives.

JsFiddle link: https://jsfiddle.net/szkfm0y7/

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Use jquery on input alongside with the on change event

$('#datepicker').datepicker()
    .on("input change", function (e) {
    console.log("Date changed: ", e.target.value);
});

Fiddle


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...