我正在尝试在我的网站上使用HTML5日期选择器标签。但是这个标签在Mozilla和IE上不支持。请问有什么方法可以让这段代码在IE和Mozilla中工作?
我想只使用HTML5,不想使用JavaScript。
我正在尝试在我的网站上使用HTML5日期选择器标签。但是这个标签在Mozilla和IE上不支持。请问有什么方法可以让这段代码在IE和Mozilla中工作?
我想只使用HTML5,不想使用JavaScript。
如果使用 Mozilla 浏览器,您可以使用 jQuery 日期选择器:使用 $.browser.mozilla 检查浏览器,但在 jQuery>1.9 中将不起作用,因此您需要使用如下所示的 jQuery 迁移:
<script src="http://code.jquery.com/jquery-1.10.2.js"></script>
<script src="http://code.jquery.com/jquery-migrate-1.2.1.js"></script>//jQuery migration
<script>
if ($.browser.mozilla)
{
if ($('.datepicker')[0].type != 'date') $('.datepicker').datepicker();
$(function () {
$(".datepicker").datepicker({
changeMonth: true,
changeYear: true,
yearRange: "1900:2015",
dateFormat: "yy-mm-dd",
defaultDate: '1900-01-01'
});
});
}
</script>
是的,HTML5的DatePicker
标签在Mozilla Firefox中不受支持。但是您可以通过添加一些.js文件在您的网站上使用DatePicker
。
以下是我的fiddle,使用了一些.js文件。这段代码在Chrome和Mozilla上都可以正常工作。
<script>
$(function() {
$( "#datepicker" ).datepicker();
});
</script>
</head>
<body>
<p>Your Selected date Is : <input type="text" id="datepicker"></p>
首先,回答问题,提问者所要求的是不可能的。需要使用 Javascript
。其次,虽然 webshim
看起来很棒,但与 bootstrap
的兼容性非常差。因此,您应该使用 http://eonasdan.github.io/bootstrap-datetimepicker/。
<!DOCTYPE html>
<html>
<body>
<form action="demo_form.asp">
Birthday: <input type="date" name="bday">
<input type="submit">
</form>
</body>
</html>
Firefox和Mozilla不支持Date-HTML5!但它很快将提供支持。
但它将在 Google Chrome、Opera 和 Safari 上平稳运行。
只需使用日期选择器 polyfill。这里有一个演示。
<script src="js/jquery.js"></script>
<script src="js-webshim/minified/polyfiller.js"></script>
<script>
//webshim.setOptions('basePath', '/js-webshim/minified/shims/');
//request the features you need:
webshim.polyfill('es5 mediaelement forms');
$(function(){
// use all implemented API-features on DOM-ready
});
</script>
<input type="date" />