bootstrap-datepicker set language globally

心已入冬 提交于 2019-12-05 03:28:09
mccannf

You can set default options for Bootstrap Datepicker by assigning them like so:

$.fn.datepicker.defaults.language = 'it';

Example below:

$(document).ready(function(){
     $.fn.datepicker.defaults.language = 'it';
});

$(document).ready(function(){
     $('.datepicker').datepicker();
});
<link href="https://cdn.jsdelivr.net/bootstrap.datepicker-fork/1.3.0/css/datepicker3.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/bootstrap.datepicker-fork/1.3.0/js/bootstrap-datepicker.js"></script>
<script src="https://cdn.jsdelivr.net/bootstrap.datepicker-fork/1.3.0/js/locales/bootstrap-datepicker.it.js"></script>
<input class="datepicker"/>

Use jQuery's extend() utility method to merge your settings into the datepicker defaults object:

$.extend( $.fn.datepicker.defaults, {format: 'dd-mm-yyyy', language: 'nl'} );
<script src="/jquery/jquery.ui.datepicker.js" type="text/javascript"></script>
<script src="/jquery/jquery.ui.datepicker-it.js" type="text/javascript"></script>

<script>
$.datepicker.setDefaults( $.datepicker.regional["it"] );

$( "#data" ).datepicker();
</script>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!