Drupal模块开发使用hook_form,我如何使用Javascript

时间:2014-06-01 20:37:25

标签: drupal module hook-form

我在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')不起作用。

我该怎么做?

1 个答案:

答案 0 :(得分:0)

在表单上使用#attached属性将cssjs添加到表单

添加css,

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

添加js,

$form['#attached']['js'] = array(
drupal_get_path('module', 'ajax_example') . '/ajax_example.js',
);
相关问题