Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/40.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在AJAX加载的html上更新css_Html_Css_Ajax_Dynamic - Fatal编程技术网

在AJAX加载的html上更新css

在AJAX加载的html上更新css,html,css,ajax,dynamic,Html,Css,Ajax,Dynamic,我正在使用JQuery从AJAX加载HTML。然后在新加载的HTML中的某些元素上触发单击事件 我在新加载的元素上设置css时遇到问题 这是代码 function updateScreen(year, month) { $.ajax({ url:'ajax_php/get_year_data.php', data: 'year=any', type: 'post', success: function(data) { $('.top-contain

我正在使用JQuery从AJAX加载HTML。然后在新加载的HTML中的某些元素上触发单击事件

我在新加载的元素上设置css时遇到问题

这是代码

function updateScreen(year, month) {
  $.ajax({
    url:'ajax_php/get_year_data.php',
    data: 'year=any',
    type: 'post',
    success: function(data) {
      $('.top-container').html(data);    

      // highlight year
      $("#" + year).click();

      // and month 
      $("#" + year + ' .' + month).click(); 

      $("#" + year + ' .' + month).css('background-color', convertHex('#9FC7F5', 20))
      console.log($("#" + year + ' .' + month).css('background-color'));
    } 
  });  
}
console.log返回我希望看到的内容,但屏幕上没有显示背景颜色的变化

谁能告诉我为什么

干杯,
乔治

你为什么要在
get_year\u data.php
上发表文章
因为这是一个getter请求,所以执行GET会更加RESTful
您可以试试这个,因为它使用了更为最新的语法:

function updateScreen(year, month) {
  $.ajax({
    type: 'POST',
    url: '/ajax_php/get_year_data.php',
    data: {year: 'any'}
  }).done(function(data) {
    $('.top-container').html(data);
    $('#'+year+' .'+month).css('background_color', 'blue');
  });
}        

并相应地更新后端。

行末尾缺少分号

$("#" + year + ' .' + month).css('background-color', convertHex('#9FC7F5', 20))

您还应该研究如何正确格式化代码-我在OP中对其进行了编辑,以显示应该对格式进行哪些更改。

这不是问题的答案,但您需要尝试正确格式化代码。缩进应该是2个空格,运算符之间应该有空格。有关更多信息,请阅读以下内容: