如何禁用Microsoft Edge中的日期选择器? [英] How do you disable the datepicker in Microsoft Edge?

查看:489
本文介绍了如何禁用Microsoft Edge中的日期选择器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个输入与type =日期,并希望禁用默认日期选择器在Microsoft Edge,因为我使用jQuery的datepicker。如何使用CSS或JavaScript禁用此功能?它在Chrome和Firefox而不是Edge上正常工作。

I have several inputs with type="date" and want to disable the default date picker in Microsoft Edge since I'm using jQuery's datepicker. How do I disable this using CSS or JavaScript? It works fine in Chrome and Firefox but not Edge. Any answers would be appreciated.

一个有效的 jsFiddle a>

HTML

<script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
<link rel="stylesheet" href="https://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="https://code.jquery.com/ui/1.11.4/jquery-ui.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/modernizr/2.8.3/modernizr.min.js"></script>

<input type="date">

JS

$(document).ready(function() {
    if (!Modernizr.inputtypes.date || $(window).width() >= 900) {
        $('input[type=date]').datepicker();
    }
});

$(window).resize(function() {
    if (!Modernizr.inputtypes.date || $(window).width() >= 900) {
        $('input[type=date]').datepicker();             
    }
    else {
        $('input[type=date]').datepicker("destroy");
    }
});

CSS

input[type=date]::-webkit-inner-spin-button, input[type=date]::-webkit-calendar-picker-indicator  {
    display: none;
    -webkit-appearance: none;   
}


推荐答案

Edge中的本机日期控制功能(虽然Chrome可以通过黑客) -

It is not possible to disable the native datepicker control functionality in Edge (although Chrome can via a hack)- yet anyway.

除非由浏览器设计,输入控件通常基于/是系统控件。这意味着输入日期戳是输入日期戳, select 下拉列表是 select 下拉列表。

Input controls, unless designed by the browser are generally based on/are system controls. This means an input datepicker is an input datepicker, and a select drop down list is a select drop down list.

大多数控件在定制方面受限,除了基本样式,如边框,填充和字体样式,以及HTML标准属性。 占位符

Most controls are limited in customisation apart from basic styling like borders, padding and font styling, and HTML-standards attributes e.g. placeholder.

您有几个选项:

保留默认的datepicker控件

这是我将推荐的选项。使用默认系统控件(+适用的样式)通常是最好的策略。这可确保最大限度的设备兼容性,以及您的用户的熟悉程度。此外,一切通常只是工作。

This is the option I will recommend. Sticking with the default system controls (+ styling where applicable) is usually the best policy. This ensures maximum device compatibility, and familiarity for your users. Plus, everything normally 'just works'.

恶意选项:浏览器检测

Evil Option: Browser Detection

您可以检测浏览器是否在您的JS代码中的Edge,然后指定它呈现jQuery控件。你应该避免这种情况,除非你真的需要它,因为浏览器检测变得过时,维护噩梦很快。

You could detect if the browser is Edge in your JS code, and then tell it to render the jQuery control instead. You should avoid this unless you really need it, as browser detection becomes out-of-date and a maintenance nightmare pretty quick.

这篇关于如何禁用Microsoft Edge中的日期选择器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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