【问题标题】:Why is bootstrap not calling the active class?为什么引导程序不调用活动类?
【发布时间】:2017-01-04 13:05:33
【问题描述】:

我通过 jQuery Ajax 接收来自 PHP 文件的信息并循环该信息,如下所示。我需要它来调用<tr class="active"> 并将它们放入引导程序提供的<tr><td> 格式中。但是,不幸的是,这并没有发生。

有人有什么建议吗?谢谢:)

function getStudentList() {
     $.ajax({    //create an ajax request to load_page.php
       type: "GET",
       url: "getView.php",             
       dataType: "json",   //expect html to be returned                
       success: function(response){                    
          $.each(response, function(index, response){

          $( "#aaa" ).append('<tr class="active"><td>' + response['Student_ID'] + '</td><td>' + response['FirstName'] + "</td><td>" + response['LastName'] + "</td><td>" + response['Student_ID'] + "</td><td>" + response['Year'] + '</td></tr>');
        });

    },
     error: function(e) {
        //called when there is an error
        console.log("Error: " + e.message);
        }
    });
}

--------- HEADER.PHP ---------------

  <!-- Database Config Files -->
<?php include('db_config.php'); ?>

<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">

<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">


<!-- Custom css -->
<link rel="stylesheet" type="text/css" href="style.css">

<!-- Latest compiled and minified JavaScript -->

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>

<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>

<script type="text/javascript" src="export.js"></script>
<script type="text/javascript" src="contact.js"></script>
<script type="text/javascript" src="view.js"></script>
<script type="text/javascript" src="create.js"></script>
<script type="text/javascript" src="edit.js"></script>
<script type="text/javascript" src="delete.js"></script>
<script type="text/javascript" src="search.js"></script>

【问题讨论】:

  • 能否在控制台显示xhr结果响应(ajax响应)?
  • 是否追加了 ow ?一个可行的例子可以帮助更多地研究这个问题
  • 如果你使用的是 Bootstrap v4,你需要在 tr 元素上使用 table-active 类。 &lt;tr class="table-active"&gt;
  • @Azy 你需要跟进你的问题。
  • [link]imgur.com/a/7lchi - 这是一个屏幕截图。该课程已添加,但尚未阅读。 @CodeGodie 我在海外道歉!上面的活动类是在 HTML 中手动完成的,其中第二个活动类是从 AJAX 附加的。 imgur.com/a/NmHm9 - 包含 JQuery 和 Bootstrap 的头文件

标签: javascript php jquery ajax twitter-bootstrap


【解决方案1】:

我建议你开始使用更好的 IDE;我推荐 PHPStorm。问题似乎是您的引号的语法。检查这些区域:

你有:

<td>' + response['Student_ID'] + '</td>

应该是:

<td>' + response["Student_ID"] + '</td>

更好:

<td>' + response.Student_ID + '</td>

【讨论】:

  • 将其更改为 response.Student_ID 仍然没有。这是因为它是一个对象吗?为什么它可以作为数组读取?从技术上讲,它正在获得预期的结果,但显然没有选择“活动”类,这很奇怪,因为在它上面是手动 HTML。那么是否有来自 AJAX 的干扰?
  • hmm.. 显示您的 PHP 代码,我将能够弄清楚。
  • 抱歉不知道如何粘贴它或一个 php 代码 bin - [
  • 在你的 PHP 中,将这个 header('Content-Type: application/json'); 放在你的 echo 之前,然后告诉我你得到了什么。
  • 天哪:/ 伙计,非常感谢。我复制了 id="aaa" 两次(白痴),它干扰了我想要的。现在我删除了它,它是固定的:/我觉得很愚蠢,非常感谢你的帮助!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-08-14
  • 1970-01-01
  • 2014-01-14
相关资源
最近更新 更多