逐步增强 html 表单,jQuery UI 日期选择器不起作用
我是逐步增强 HTML5 表单的新手,目前正在尝试使用 jQuery UI 和 HTML5 的新输入类型来创建跨浏览器表单。我正在使用 Modernizr 和 Yepnope 用于条件加载脚本和以下教程 CSS-tricks.com。但我收到 Object [object Object] has no method 'datepicker'
错误。
我发现有 Modernizr.load()
可以用来代替 yepnope()
,但这不起作用,最终得到 Object #< ;对象>没有方法“load”
错误,所以我回到了yepnope()
。以下是网页的 部分。
<Head>
<title>HTML5 Web Form</title>
<script type="text/javascript" src="js/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="js/modernizr-2.5.2.js"></script>
<script type="text/javascript" src="js/yepnope.1.5.2-min.js"></script>
<script type="text/javascript" src="js/custom.js"></script>
<script type="text/javascript">
yepnope({
test: Modernizr.inputtypes.date,
nope: [
"./js/jquery-ui-1.8.17.custom.min.js",
"./css/jquery-ui-1.8.17.css"
]
});
$(function(){
$("input[type='date']").datepicker(); //this is giving error
});
</script>
</Head>
有一个带有
的表单
经过一番谷歌搜索后,我发现了这个原因错误是加载了两次 jQuery Core,我也跟着 这个,但无法解决问题。
谢谢。
注意:我正在 Chrome 17 和 Opera 11.61 中测试该页面。
I'm new to progressively enhancing HTML5 forms, and I'm currently trying jQuery UI and HTML5's new input types to create cross-browser forms. I'm using Modernizr and Yepnope for conditional loading of scripts and following tutorial given at CSS-tricks.com. But I'm getting Object [object Object] has no method 'datepicker'
error.
I found that there's Modernizr.load()
which can be used in place of yepnope()
, but that didn't worked and ended up with Object #<Object> has no method 'load'
error so I went back to yepnope()
. Below is by <Head>
section of the webpage.
<Head>
<title>HTML5 Web Form</title>
<script type="text/javascript" src="js/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="js/modernizr-2.5.2.js"></script>
<script type="text/javascript" src="js/yepnope.1.5.2-min.js"></script>
<script type="text/javascript" src="js/custom.js"></script>
<script type="text/javascript">
yepnope({
test: Modernizr.inputtypes.date,
nope: [
"./js/jquery-ui-1.8.17.custom.min.js",
"./css/jquery-ui-1.8.17.css"
]
});
$(function(){
$("input[type='date']").datepicker(); //this is giving error
});
</script>
</Head>
And the <body>
has a form with <input type='date' name='dtTest'/>
After a bit Googling, I found that cause for the error is loading of jQuery Core twice, I also followed this, but can't fix the issue.
Thanks.
Note: I'm testing the page in Chrome 17 and Opera 11.61.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的 HTML 页面应如下所示:
datepicker.js 的内容应为:
这在我的 Chrome 副本上运行良好,尽管我没有机会在其他浏览器中检查它。
更新:我们可以通过更有效地使用 yepnope 的
callback
块并绑定datepicker()< 来避免使用单独的
datepicker.js
/code> 本身。Here's what your HTML page should look like:
And the content of datepicker.js should be:
This works fine on my copy of Chrome, though I've not had the chance to check it in other browsers.
Update: We can avoid using separate
datepicker.js
by making use ofcallback
block of yepnope more efficiently and bindingdatepicker()
there itself.