0

我正在 Drupal 中创建我的第一个模块。我创建了一个.module具有以下功能的文件hook_menu

    $items['admin/config/module'] = 
    array(
        'title' => 'Module',
        'description' => 'module Management',
        'page callback' => 'drupal_get_form',
        'page arguments' => array('module_form'),
        'access arguments' => array('administer module for other applications'),
        'weight' => 9999,
        'file' => 'module.admin.inc',
    );
return $items;

JavaScript 在这个.module文件中工作

此代码链接到module.admin.inc呈现我的表单的另一个文件,该表单正确呈现。但是,当我想使用 AJAX 显示一些数据时,我不能。

它接缝drupal_add_js('path')不起作用。

我该怎么做呢?

4

1 回答 1

0

Use #attached property on form to add css or js to form

To add css,

$form['#attached']['css'] = array(
drupal_get_path('module', 'ajax_example') . '/ajax_example.css',
);

To add js,

$form['#attached']['js'] = array(
drupal_get_path('module', 'ajax_example') . '/ajax_example.js',
);
于 2014-06-02T11:38:11.117 回答