jquery datepicker-覆盖数据属性中的选项
我正在使用这个标记jquery datepicker-覆盖数据属性中的选项,jquery,jquery-ui,jquery-ui-datepicker,custom-data-attribute,Jquery,Jquery Ui,Jquery Ui Datepicker,Custom Data Attribute,我正在使用这个标记 <label> Date <input type="text" data-datepicker="{maxDate: '+1d'}" /></label> <label> Another date <input type="text" data-datepicker="" /></label> <script> $('[data-datepicker]').each(function() {
<label> Date <input type="text" data-datepicker="{maxDate: '+1d'}" /></label>
<label> Another date <input type="text" data-datepicker="" /></label>
<script>
$('[data-datepicker]').each(function() {
// init the options var with some default values (dateFormat etc)
// that can be overridden by the data-datepicker values
// also, new values can be added to the options from data-datepicker
// such as in the above example "maxDate"
var options = TODO;
$(this).datepicker(options);
});
</script>
但是我如何使用数据属性中的值添加/覆盖。。我只是不知道使用这个标记(您必须像这样格式化“data”属性,以便它们被识别为对象):
在这里拉小提琴:
var options = { dateFormat: 'yy-mm-dd };
<label> Date <input type="text" data-datepicker='{"maxDate": "+1d"}' /></label>
<label> Another date <input type="text" data-datepicker='{ "dateFormat": "dd-mm-yy"}' /></label>
$('[data-datepicker]').each(function() {
//standard options
var options = { dateFormat: "yy-mm-dd"};
//additional options
var additionalOptions = $(this).data("datepicker");
//merge the additional options into the standard options and override defaults
jQuery.extend(options, additionalOptions);
$(this).datepicker(options);
});