怎么做成input选择立即执行


<input class="form-control js-datepicker m-b-10" type="text" id="example-datepicker" name="example-datepicker" placeholder="yyyy-mm-dd" value="" data-date-format="yyyy-mm-dd" />

我有一个这样的Input日期选择框,怎么做成选择立刻执行 /index.php?date=日期

<input class="form-control js-datepicker m-b-10" type="text" id="example-datepicker" name="example-datepicker" placeholder="yyyy-mm-dd" value="" data-date-format="yyyy-mm-dd" />

<script>
  // 获取日期选择器元素
  const datepicker = document.getElementById('example-datepicker');

  // 监听日期选择器值的更改
  datepicker.addEventListener('change', function() {
    // 构造重定向URL
    const url = '/index.php?date=' + datepicker.value;

    // 重定向到URL
    window.location.href = url;
  });
</script>

datepicker有个点击确定触发的方法的,你在自定义的方法里面执行就好了

您好,我是有问必答小助手,您的问题已经有小伙伴帮您解答,感谢您对有问必答的支持与关注!
PS:问答VIP年卡 【限时加赠:IT技术图书免费领】,了解详情>>> https://vip.csdn.net/askvip?utm_source=1146287632