You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用easepick插件时,日期范围选择回调事件无法触发的求助

解决easepick日期范围选择后不触发事件的问题

用easepick的RangePlugin实现日期范围选择时,原生input的change事件不生效是因为插件在autoApply: true模式下,不会主动触发原生的change事件,得用插件自带的select事件来监听选择完成的动作。

有两种绑定方式:

  1. 初始化picker时直接配置onSelect回调
    修改你的enableEasepick函数,在配置对象里添加onSelect属性:
enableEasepick = function() {
  const picker = new easepick.create({
    element: document.getElementById('datepicker'),
    grid: 2,
    zIndex: "1000",
    calendars: 2,
    css: [
      'https://cdn.jsdelivr.net/npm/@easepick/bundle@1.2.1/dist/index.css'
    ],
    plugins: ['RangePlugin', 'LockPlugin'],
    RangePlugin: {
      tooltipNumber(num) {
        return num - 1;
      },
      locale: {
        one: 'night',
        other: 'nights',
      },
    },
    LockPlugin: {
      minDate: new Date(),
      minDays: 2,
      inseparable: true,
    },
    autoApply: true,
    // 添加选择完成后的回调
    onSelect: function(e) {
      // e.detail包含选中的日期范围数据
      const { start, end } = e.detail;
      console.log('开始日期:', start);
      console.log('结束日期:', end);
      // 这里编写你的业务逻辑
    }
  });
};
  1. 初始化后通过on方法绑定select事件
    如果需要后续动态绑定或外部绑定,可使用这种方式:
enableEasepick = function() {
  const picker = new easepick.create({
    // 你的原有配置...
    autoApply: true,
  });

  // 绑定select事件
  picker.on('select', function(e) {
    const { start, end } = e.detail;
    console.log('选中的日期范围:', start, end);
    // 执行你的业务逻辑
  });
};

配置完成后,用户选好日期范围时就会触发对应的事件处理逻辑。

内容的提问来源于stack exchange,提问作者Cjoerg

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.10 21:08:08