logo

Palette - Make it Colorful🎨

Palette - Visual Page Builder, no design degree required.

Live Demo Download Palette

滚动

Drupal 与 jQuery。第8课:在 Drupal 7 中集成 jQuery UI 和 jQuery UI Tabs

10/10/2025, by Ivan

文件代码

/sites/all/modules/custom/custom.info

name = custom
description = custom module
core = 7.x

/sites/all/modules/custom/custom.module

<?php
 
  drupal_add_library('system', 'ui.tabs');

CSS代码:

#tabs{
  border: 0px;
}
 
.ui-tabs-nav{
  background: none;
  border: none;
}

在 node-product.tpl.php 中的 HTML 代码:

<div id="tabs">
      <ul>
        <li>
          <a href="#tabs-1">描述</a>
        </li>
        <li>
          <a href="#tabs-2">特征</a>
        </li>
      </ul>
 
      <div id="tabs-1">
        <?php
          print render($content['body']);
        ?>
      </div>
      <div id="tabs-2">
        <?php
          print render($content);
        ?>
      </div>
    </div>

首先,需要创建一个自定义模块。

https://rupalbook.org/content/iz-chego-sostoit-modul-drupala

接下来需要将 custom 模块的权重设置得比核心模块更高。为此,请通过 phpMyAdmin 打开数据库,并在 system 表中将模块的 weight 值设置为 100 或更高。模块记录位于 system 表中:

System db table

现在,可以在 custom 模块中加载 jQuery UI 插件,例如:

<?php
drupal_add_library('system', 'ui.tabs');
drupal_add_library('system', 'ui.accordion');

可以在模块开头(PHP 开始标签之后)直接插入这段代码。