A-A+
jQueryui datepicker时间控件在动态创建表单中的使用
datepicker是一个不错的日期插件了,我们今天一起来看看jQueryui datepicker时间控件在动态创建表单中的使用吧,希望文章能够对各位有帮助.
例子:
- <script>
- //页面初始化
- $(document).ready(function() {
- //固定表单
- $('#contract_date').datepicker();
- //动态表单
- $('.datepicker').live('click', function() {
- $(this).datepicker({showOn:'focus'}).focus();
- });
- });
- </script>
默认功能:
日期选择器(Datepicker)绑定到一个标准的表单 input 字段上,把焦点移到 input 上(点击或者使用 tab 键),在一个小的覆盖层上打开一个交互日历,选择一个日期,点击页面上的任意地方(输入框即失去焦点),或者点击 Esc 键来关闭,如果选择了一个日期,则反馈显示为 input 的值.
- <!doctype html>
- <html lang="en">
- <head>
- <meta charset="utf-8">
- <title>jQuery UI 日期选择器(Datepicker) - 默认功能</title>
- <link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
- <script src="//code.jquery.com/jquery-1.9.1.js"></script>
- <script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
- <link rel="stylesheet" href="http://jqueryui.com/resources/demos/style.css">
- <script>
- $(function() {
- $( "#datepicker" ).datepicker();
- });
- </script>
- </head>
- <body>
- <p>日期:<input type="text" id="datepicker"></p>
- </body>
- </html>