本文主要是介绍jquery的datepicker,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
更详细介绍官网:http://jqueryui.com/demos/datepicker/第一次使用jquery的datepicker时,找了很久才找到怎么设置中文,今天重新学习了一下,原来jquery已经自带好了,在jquery根目录/development-bundle/ui/i18n/每个国家相对于的语言js文件,简体中文的为jquery.ui.datepicker-zh-CN.js。
<link href="jquery/css/jquery-ui-1.8.16.custom.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery/js/jquery-1.6.2.min.js"></script>
<script type="text/javascript" src="jquery/js/jquery-ui-1.8.16.custom.min.js"></script>
<script type="text/javascript" src="jquery/jquery.ui.datepicker.js"></script>
<script type="text/javascript" src="jquery/jquery.ui.datepicker-zh-CN.js"></script>//包含它后就会显示中文
<script>
$(function(){
$("#datapicker").datepicker({
disabled:false,
altField:'#alt',//与改日期相关联的日期
altFormat:'y-m-d',//相关联日期的格式
appendText:'(yyyy-mm-dd)',//
autoSize:true,
changeMonth:true,
changeYear:true,
dateFormat:'yy/mm/dd',//初始化时的日期格式
duration: 'fast',//这个日期插件显示的速度{'slow','normal','fast'}
showButtonPanel: true ,//增加‘今天’、‘关闭’按钮在底部
showOn: 'button',//展示方式,‘focus’,‘button’,'both',默认为focus
});
})
</script>
</head>
<body style="font-size:62.5%;">
<input type="text" id="datapicker">
<input type="text" id="alt">
</body>
获取datepicker的任意option的值:$("#datapicker").datepicker('option','name');//name为option的名字,如'dateFormat';
设置datepicker的某个属性的值:$("#datapicker").datepicker('option','name','value');
功能函数:
1 $.datepicker.setDefaults();//设置所有的datepicker插件的默认属性,当一个页面中有多个datepicker插件时可以通过该函数设置所有插件都有的属性。例如:
$.datepicker.setDefaults(
{ showOn:'both',
buttonText:'日期',
}
$.datepicker.setDefaults($.datepicker.regional['zh']);//设置所有的日期插件显示为中文
2 $.datepicker.formatDate(format,date,settings).设置日期格式
这篇关于jquery的datepicker的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!