【问题标题】:Dynamically change text color with jquery and ajax, with different colors, different text and having same attribute/class使用 jquery 和 ajax 动态更改文本颜色,具有不同的颜色、不同的文本和具有相同的属性/类
【发布时间】:2019-05-22 09:43:21
【问题描述】:

我在视图上创建了动态数据的表结构,但我想在不同的付款状态上添加不同的颜色,并且它们在每个付款状态上都有相同的类,但是当我点击第 1 或 2 或 3 页时,它只显示在单个页面不是在每个页面上。我想在所有页面上显示它。

$(document).ready(function() {
  $('.paginate_button a').click(function() {
    $.ajax({
      url: "",
      method: "POST",
      data: $("#DataTables_Table_0 td .custom-text-badge"),
      success: function(data) {
        $("#DataTables_Table_0 td .custom-text-badge:contains('Success')").css({
          "color": "red"
        });
        $("#DataTables_Table_0 td .custom-text-badge:contains('pending')").css({
          "color": "green"
        });
      }
    });
  });
});

this is image link for payment success and pending text color

this image link for pagination

this image link when click on another page link 2/3 ect no color shown

【问题讨论】:

    标签: jquery ajax datatables


    【解决方案1】:

    尝试使用该属性创建一个类:

    .red{
      color: red,
     }
    

    如果您想在一行上添加自定义格式,请直接在该回调中添加用于格式化 CSS 的类。

        $(document).ready(function() {
      $('.paginate_button a').click(function() {
        $.ajax({
          url: "",
          method: "POST",
          data: $("#DataTables_Table_0 td .custom-text-badge"),
          success: function(data) {
            $("#DataTables_Table_0 td .custom-text-badge:contains('Success')").addClass("red");
            $("#DataTables_Table_0 td .custom-text-badge:contains('pending')").addClass("red");
          }
        });
      });
    });
    

    【讨论】:

      猜你喜欢
      • 2022-09-27
      • 2011-02-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-23
      • 1970-01-01
      • 2016-04-21
      相关资源
      最近更新 更多