2

我遵循了一些教程和书籍来使用 html5表单。我使用modernizr为不支持的浏览器提供了一个后备。万事皆安。事情甚至在 IE6 中工作。我面临 jquery datepicker ui 的问题。目前只有opera支持input type="date"(我使用的是最新版本的opera)。


尽管我使用modernizr来检测浏览器对input type="date"的支持,但不知何故,opera 仍在加载 jquery datepicker。我做错什么了吗??...我应该按特定顺序包含脚本吗??...


这是我编写的代码,后面是问题的屏幕截图。

html标记:

<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>date picker</title>
<link rel="stylesheet" href="jquery-ui/css/redmond/jquery-ui-1.8.20.custom.css"/>
</head>
<body>
<form>
    <input type="date" name="date-picker" id="date-picker" value="2010-10-06" />
</form>
<script src="modernizr.js"></script>
<script src="webforms/webforms2.js"></script>
<script src="jquery.js"></script>
<script src="jquery.ui.core.min.js"></script>
<script src="jquery.ui.datepicker.min.js"></script>
<script src="custom.js"></script>
</body>
</html>

jQuery代码:

$(document).ready(function(){
    if(!Modernizr.inputtypes.date){
        $('input[type=date]').each(function() {
        var $input = $(this);
        $input.datepicker({
            minDate: $input.attr('min'),
            maxDate: $input.attr('max'),
            dateFormat: 'yy-mm-dd'
        });
    });
 }  
});

截屏:

http://imageshack.us/photo/my-images/16/operadatepicker.jpg/

源代码:媒体火下载链接

4

1 回答 1

1

Modernizr.inputtypes.date在 Opera 11 中按预期工作:

http://jsfiddle.net/feeela/tMUcw/

也许错误是,您没有在 Modernizr 的构建中包含“输入类型”。去下载开发者版本或构建自定义下载,但请确保包含“输入类型”。

http://modernizr.com/download/

于 2012-06-01T14:59:10.410 回答