如何在没有 jquery/javascript 的情况下为 HTML5 日期字段添加验证/限制

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8574442/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 03:51:03  来源:igfitidea点击:

How to add validation/restrictions for HTML5 date field without jquery/javascript

javascripthtml

提问by kvc

Is it possible to add validations/restrictions to date element using HTML api,without jquery?

是否可以在没有 jquery 的情况下使用 HTML api 向日期元素添加验证/限制?

I am currently using jquery datePicker to display calendar,and for adding restrictions using the beforeShow method of the datePicker.

我目前正在使用 jquery datePicker 来显示日历,并使用 datePicker 的 beforeShow 方法添加限制。

Now i am trying to use the HTML5 calender and want to know how to add restrictions(eg:disable weendends/holidays) to the HTML5 calendar. Can somebody point me in right direction?

现在我正在尝试使用 HTML5 日历并想知道如何向 HTML5 日历添加限制(例如:禁用周末/假期)。有人可以指出我正确的方向吗?

回答by Romain Meresse

You can use minand maxattributes on your date input.

您可以在日期输入中使用minmax属性。

Spec : http://www.w3.org/TR/html-markup/input.date.html

规格:http: //www.w3.org/TR/html-markup/input.date.html

Edit :

编辑 :

  • Afaik,无法使用 HTML5 日期输入禁用特定日期...

  • 如果您想跨浏览器,请使用Modernizr并为旧浏览器提供后备(例如 jQuery datePicker):http://net.tutsplus.com/tutorials/html-css-techniques/how-to-build-cross -browser-html5-forms/