【发布时间】:2013-10-16 07:25:32
【问题描述】:
您好,我无法显示放置在表格中的月份选择器。
<!DOCTYPE html>
<head>
<script src="js/libs/jquery-1.9.1.js"></script>
<link rel="stylesheet" href="css/jquery-ui.css" />
<script src="js/libs/jquery-ui-1.10.3.custom.min.js"></script>
$(function() {
$('.date-picker').datepicker( {
changeMonth: true,
changeYear: true,
showButtonPanel: true,
dateFormat: 'MM yy',
onClose: function(dateText, inst) {
var month = $("#ui-datepicker-div .ui-datepicker-month :selected").val();
var year = $("#ui-datepicker-div .ui-datepicker-year :selected").val();
$(this).datepicker('setDate', new Date(year, month, 1));
}
});
});
</script>
<script>
window.onload = function () {
PreLoadSection();
</script>
<style>
.ui-datepicker-calendar {
display: none;
}
</style>
</head>
<body>
<div id="variables" name="variables" style="width:100%; overflow:auto; overflow: scroll;">
</div>
</body>
</html>
上面是我的 htm 代码,下面是我的 .js 文件
function PreLoadSection()
{
LoadSectionStratified();
}
function LoadSectionStratified() {
$('#variables').append($('<table id="variables_table">'));
$('#variables').append($('<tr>'));
$('#variables').append('<th style="border: 10px">month picker</th>');
$('#variables').append($('</tr>'));
$('#variables').append($('<tr>'));
AddDate_MonthYear_StratifiedSection();
$('#variables').append($('</tr>'));
$('#variables').append($('</table>'));
$('#variables').trigger('create');
}
function AddDate_MonthYear_StratifiedSection() {
table_html = '<td style="min-width: 200px;"><input name="name1" id="id1" value="" class="date-picker"></td>';
$('#variables').append(table_html);
}
上面的代码是我如何实现它但它不起作用。我正在使用 Firefox 24 版。 在窗口加载时,我调用调用 LoadSectionStratified 函数的预加载函数
【问题讨论】:
-
显示一个完整示例,包括包含的库和变量定义(
control_id等)。查看JavaScript error console 并告诉您在那里看到的错误以及它们指向的行。 -
datepicker 不是 jQuery 函数,它包含在 jQueryUI 中。你还记得在 jQuery 之后加载 jQueryUI 吗?您可能还想在 javascript 和 jquery 之后将 jQuery UI 作为标签附加到您的问题中。
-
@Juhana -我试图编辑代码希望它对你有意义,因为它是一个非常大的程序,并且大部分代码都引用了其他东西,使它成为一个获取所有内容的长链跨度>
-
@Eirinn-i 在 jQuery 之后包含了 jQueryUI,如上面编辑的代码所示
-
在我看来,您正试图在输入元素存在之前初始化日期选择器。你什么时候打电话给
LoadSectionStratified()?
标签: javascript jquery jquery-ui jquery-ui-datepicker