实际上我有两个问题
1-我试图突出显示日历中的某些日期,但是除非单击日历,否则样式将无法在页面加载后起作用
2-当我保存一些文本时,我想刷新日历以突出显示这个新的事件日期,如果我只是想起该函数什么都没发生,也许是因为我已经初始化了数据选择器
对于第一个问题,我在初始化日期选择器后尝试添加这些命令
-$('#datepicker').datepicker("refresh");
- function EventDates() {
var apiURL = '@Url.Content("~")api/GeDate';
var eventDates = {};
$.ajax({
url: apiURL,
success: function (data) {
$.each(data, function (i, item) {
//alert(item.Date1)
eventDates[new Date(item.Date1)] = new Date(item.Date1);
});
}
})
// datepicker
$('#datepicker').datepicker({
numberOfMonths: [3, 1],
dateFormat: "mm/dd/yy",
onSelect: function (dateText, inst) {
jQuery('#calendar_date').val(dateText);
CheckDate();
},
beforeShowDay: function (date) {
var highlight = eventDates[date];
if (highlight) {
return [true, "event", 'There is a text'];
} else {
return [true, '', ''];
}
}
});
// $('#datepicker').datepicker("refresh");
}
-function Save()
{
var params = [];
// globalDeptID
params.push({ name: "Date", value: $('#calendar_date').val()});
params.push({ name: "Message_E", value:$('#EN').val() });
params.push({ name: "CreatedBy", value: '@ViewBag.ID' });
params.push({ name: "ModifiedBy", value: '@ViewBag.ID'});
var apiURL = '@Url.Content("~")api/InsertAndUpdate';
$.ajax({
url: apiURL,
data: params,
type: "POST",
success: function (data, textStatus, jqXHR) {
swal("Success", "The message has been saved successfully.", "success"); EventDates();
$("#datepicker").datepicker("refresh");
},
error: function (err) {
//alert("An error occured. Could not submit your request.");
swal({
text: "An error occured.",
icon: "error"
});
}
})
}
这是获取活动日期的代码
EventDates();
$("#datepicker").datepicker("refresh");
if answer == "2":
f = open("users.txt", "r")
x = str(input("Please enter a valid username: "))
for line in f:
usernab = print(line.strip())
if (x) in (usernab):
for x in range(0,5):
#Do something.
如您在保存功能中看到的那样,我在保存数据后回想起eventDates的功能
Traceback (most recent call last):
File "E:/NEA/Project/backup.py", line 20, in <module>
if (x) in (usernab):
TypeError: argument of type 'NoneType' is not iterable
答案 0 :(得分:0)
我找到了解决两个问题的方法
我将datepicker放入ajax调用中,对于第二个问题,我销毁了datepicker,然后重新初始化了
$("#datepicker").datepicker("destroy");
EventDates();