Flatpickr 清除按钮 [英] Flatpickr Clear Button
本文介绍了Flatpickr 清除按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用这个加载 flatpickr:
I'm loading flatpickr using this:
<script type="text/javascript">
jQuery(document).ready(function($){
$('#Mydatetime').flatpickr({
altInput: true,
altFormat: "M j, Y @ H:i",
enableTime: true,
dateFormat: 'Y-m-d\\TH:i'
});
});
<input type="text" id="Mydatetime" class="MyDate" name="my_expire_date" value="' . $variable . '"/>
变量只是我的日期时间.它有效,但我想添加一个类似于 this.无论我做什么,按钮都不会清除日期.
The variable is just my datetime. It works, but I'd like to add a clear button similar to this. No matter what I do the button doesn't clear the date.
例子:
<a class="input-button" title="clear" data-clear>
<i class="icon-close"></i>
</a>
看起来很简单,但我显然遗漏了一些东西.有人让这些关闭按钮之一正常工作吗?
Seems straightforward, but I'm clearly missing something. Anyone got one of these close buttons working properly?
推荐答案
@Ayxan 的回答是不对的,它所做的是创建一个 flatpickr 的新实例并在其上调用 clear()
.最重要的是,它不会清除实际存储日期的隐藏输入字段.
Answer by @Ayxan is not right, what it's doing is making a new instance of flatpickr and calling clear()
on it. Most importantly it doesn't clear the hidden input fields that actually stores the date.
使用以下方法:
const $flatpickr = $("#flatpickr_id").flatpickr();
$("#some_button_id").click(function() {
$flatpickr.clear();
})
这篇关于Flatpickr 清除按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文