javascript - JQuery - 根据数据库中的值使用 ajax 突出显示元素

标签 javascript php jquery mysql ajax

好的,所以我查看了文档并用 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/

相关文章:

php - 在 MySQL 中保存为 BLOB 后获取不同的图像

javascript - JQuery 数据表列溢出

javascript - Jquery javascript 关联数组

javascript - 如何为移动设备制作导航栏

javascript - 确定当天的开始和结束时间 (UTC) (JAVASCRIPT)

javascript - 这似乎是 Javascript 事件的一个类。它是什么?

php - Lumen 数据库播种错误

javascript - 使用字符串数组中找到的键添加/删除数组对象

php - Wordpress 二十十二全屏响应式背景图片

javascript - 包装已经创建的元素(之后,之前等)?