在 jQuery 日期选择器上收听 onChange? [英] Listening to onChange on a jQuery datepicker?

查看:14
本文介绍了在 jQuery 日期选择器上收听 onChange?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在创建一个这样的日期选择器

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);
});

我的目标是能够在用户清除日期框时进行监听.但是,更改事件似乎只有在您取消关注日期框后才会触发.我想知道是否有办法侦听 jQuery 日期框中的所有更改,或者是否有更好的替代方法.

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 链接:https://jsfiddle.net/szkfm0y7/

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

推荐答案

使用 jquery on input 和 on change 事件

Use jquery on input alongside with the on change event

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

小提琴

这篇关于在 jQuery 日期选择器上收听 onChange?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆