简体   繁体   English

AnyTime datepicker添加清除按钮

[英]AnyTime datepicker add a clear button

I am a new to js and am trying to figure out if there is a way to either modify an existing button within AnyTime Datepicker or add a new one that will clear the date from the field. 我是JS的新手,正在尝试弄清是否有办法修改AnyTime Datepicker中的现有按钮,或添加新的按钮来清除字段中的日期。

I see this as a possible solution, but can't figure out where to insert it into the anytime.js to prevent the AnyTime datepicker from breaking: 我认为这是一种可能的解决方案,但无法弄清楚将其插入到anytime.js中以防止AnyTime datepicker中断:

}).keyup(function(e) {
    if(e.keyCode == 8 || e.keyCode == 46) {
        $.datepicker._clearDate(this);
    }
});

Okay, so I have below that works in Chrome / firefox, but not in IE 9. In IE 9 I click on Clear button and it brings up the date picker. 好的,因此我在Chrome / firefox中具有以下功能,但不适用于IE9。在IE 9中,单击“清除”按钮,它将弹出日期选择器。 If I click on it twice in IE it will clear the field. 如果我在IE中单击两次,它将清除该字段。 How can I get it to be compatible with IE9: 如何获得与IE9兼容的信息:

<tr>
                        <td>
                            <label class="width100 right displayInlineBlock padBottom5">Received:
                                <input class="width70 calendarBackground" type="text" maxlength="4000" name="received" id="received" value="<%=report.getFormattedReceived()%>" />
                                <script>
                                    AnyTime.picker( "received", { format: "%d %b %y", firstDOW: 1 } );
                                </script>
                                <input type="button" id="receivedClear" value="Clear" />
                                <script>
                                    $("#receivedClear").click( function(e) {
                                    $("#received").val("").change(); } );
                                </script>
                            </label>
                        </td>
                    </tr>

Thanks! 谢谢!

The problem is, the picker appears when the date field has focus, and it constantly updates the field to show the currently-selected date (which defaults to the current date when empty). 问题在于,当日期字段具有焦点时,选择器出现,并且它不断更新该字段以显示当前选择的日期(如果为空,则默认为当前日期)。 Therefore, calling change() to bring up the picker should, by design, also populate the field with the current date/time. 因此,根据设计,调用change()以调出选择器还应使用当前日期/时间填充该字段。

If you want to clear the field, you should just call val('') and not bring up the picker. 如果要清除该字段,则应仅调用val('')而不启动选择器。 If you want to display the picker, then you should either not clear the field, or be willing to accept that the picker will reset the field to the current time. 如果要显示选择器,则应该不清除该字段,或者愿意接受选择器会将字段重置为当前时间。

I am working on a new picker that will not automatically update the field until the picker is dismissed, but it is still many months from release. 我正在研究一个新的选择器,直到关闭该选择器后它不会自动更新该字段,但是距离发布还有很多个月。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM