好的,所以我查看了文档并用 Google 搜索了这个,但令人惊讶的是我找不到解决方案,而且似乎没有人遇到与我相同的问题。我是 JQuery AJAX 的新手,我正在从头开始整理一种预订日历,我正在寻找一种方法来根据“日期”是否在数据库中进行预订来突出显示日历 GUI 中的元素或“日期” .这是我正在修改的 JQuery block ,但由于某种原因我觉得我离题太远了。
$(".box").load(function() {
date_time = $(this).attr('id');
month = $(this).attr('month');
year = $(this).attr('year');
$.ajax({
type: 'GET',
url: '/book.me/check.php',
data: "date=" + date_time + "&month=" + month + "&year=" + year,
success: function(msg) {
$(this).css("background-color", "#cccccc");
}
});
});
如有任何帮助,我们将不胜感激。
最佳答案
您成功指向了不同的对象。如果您打算突出显示 ,请使用
如下所示。var that = $(this);
和 that.css("background-color", "#cccccc");
。框
$(".box").load(function() {
var that = $(this);
date_time = $(this).attr('id');
month = $(this).attr('month');
year = $(this).attr('year');
$.ajax({
type: 'GET',
url: '/book.me/check.php',
data: "date=" + date_time + "&month=" + month + "&year=" + year,
success: function(msg) {
that.css("background-color", "#cccccc");
}
});
});
关于javascript - JQuery - 根据数据库中的值使用 ajax 突出显示元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22495959/