我需要更新function.php文件,使其显示99年而不仅仅是20年。我正在使用Bizberg主题。
我尝试了这个方法,但没有成功扩展时间范围,问题在于滚动条仍然只允许20年,我需要99年。
function extend_date_of_birth_range() {
?>
<script>
jQuery(function($) {
var currentYear = new Date().getFullYear();
var startYear = currentYear - 99;
var endYear = currentYear - 10;
// Replace "billing_date_of_birth" with the ID or name of your date of birth field
$('#billing_date_of_birth').datepicker('option', {
yearRange: startYear + ':' + endYear
});
});
</script>
<?php
}
add_action('wp_footer', 'extend_date_of_birth_range');
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
试一下这个
将"dateRange"变量放置如下:
// Replace "billing_date_of_birth" with the ID or name of your date of birth field $('#billing_date_of_birth').datepicker('option', { yearRange: dateRange });将此函数添加到function.php文件中,希望这能帮到你。
<?php function extend_date_of_birth_range() { ?> <script> jQuery(function($) { var currentYear = new Date().getFullYear(); var startYear = currentYear - 99; var endYear = currentYear - 10; var dateRange = '"'+startYear+' : '+endYear+'"'; // Replace "billing_date_of_birth" with the ID or name of your date of birth field $('#billing_date_of_birth').datepicker('option', { yearRange: dateRange }); }); </script> <?php } add_action('wp_footer', 'extend_date_of_birth_range'); ?>