php - dynamic tab bootstrap creation doesn't work well
问题描述
I created a dynamic bootstrap tab with a specific tab to insert in the administration inside description field. The problem when I want to display the information inside the catalog, it display in the first tab all the text If I click on the tab I have no problem, the information is correct after
<tabCatalog>
and </tabCatalog>
are the element allow to create the dynamic tab on the catalog include include inside the text.
$desc = $this->getProductsDescription();
$product_tab_title = '<div id="categoriesTabs" style="overflow: auto;">';
$product_tab_title .='<ul class="nav nav-tabs flex-column flex-sm-row" role="tablist" id="myTab">';
if (strpos($desc, '<tabCatalog>') !== FALSE) {
$cut = explode('<tabCatalog>', trim($desc));
$c = 0;
foreach ($cut as $k => $part) {
if (trim($part) != '') {
if (strpos($part, '</tabCatalog>') !== FALSE) {
$t = substr($part, 0, strpos($part, '</tabCatalog>'));
if ($k = 0) {
$class = 'nav-link active';
} else {
$class = 'nav-link';
}
$product_tab_title .= '<li class="nav-item"><a href="#tab' . $c . '"role="tab" data-toggle="tab" class="' . $class . '">' . $t . '</a></li>';
}
}
$c++;
}
}
$product_tab_title .= '</ul>';
$product_tab_title .= '</div>';
$product_tab_description = '<div>';
$product_tab_description .= '<div class="tab-content">';
if (strpos($desc, '<tabCatalog>') !== FALSE) {
$cut = explode('<tabCatalog>', trim($desc));
$n = 0;
foreach ($cut as $n => $part) {
if (trim($part) != '') {
if (strpos($part, '</tabCatalog>') !== FALSE) {
$r = substr($part, strpos($part, '</tabCatalog>') + 13);
$product_tab_description .= '<div class="tab-pane active" id="tab' . $n . '">' . $r . '</div>';
}
}
$n++;
}
}
// content tab
$products_description_content = '<!-- Start products_description_tab -->' . "\n";
$products_description_content .= '<div class="col-md-' . $content_width .'">';
$products_description_content .= '<div class="separator"></div>';
$products_description_content .= '<div class="contentText">';
$products_description_content .= $product_tab_title;
$products_description_content .= $product_tab_description;
$products_description_content .= '<div>';
$products_description_content .= '<div>';
$products_description_content .= '<div>';
$products_description_content .= '<div>';
$products_description_content .= '<!-- end products_description_tab -->' . "\n";
echo $products_description_content
解决方案
Both tabs have the active
class...
foreach ($cut as $n => $part) {
if (trim($part) != '') {
if (strpos($part, '</tabCatalog>') !== FALSE) {
$r = substr($part, strpos($part, '</tabCatalog>') + 13);
$product_tab_description .= '<div class="tab-pane active" id="tab' . $n . '">' . $r . '</div>';
}
}
$n++;
}
I suggest you to remove active
from the class list in that loop and add that tiny jQuery script on document ready:
$(document).ready(function(){
$(".tab-pane").first().addClass("active");
});
Or .eq(1)
(zero-based) instead of .first()
if you prefer having the second tab active on page load.
推荐阅读
- node.js - 节点应用程序路由和nginx位置如何匹配?
- pandas - 使用相等的重复项制作枢轴
- c++ - 对 Vector 元素的 push_back 操作 (C++)
- angular - 将数据从组件发送到另一个组件
- azure - Azure Databricks 中 DBFS 的数据大小限制是多少
- javascript - 单击按钮时,如何为网站上的所有链接添加下划线?
- mysql - 用于更新特定记录的 SQL 语句,但如果该记录在列中包含某个值,则忽略该记录
- javafx - Javafx XYChart设置Y轴十进制值创建更多小数
- excel - 我需要这种匹配方法来跳过空白单元格而不是将它们作为匹配值包含在内
- django-rest-framework - 在 drf 中使用 django-filter 覆盖列表方法