【发布时间】:2015-02-25 03:25:33
【问题描述】:
我正在尝试编写自己的 Drupal 模块,并且我想要包含 Javascript。我尝试包含一个非常简单的 jquery 文件,但我不断收到 Uncaught 'TypeError: undefined is not a function'。 我已经更新了 Drupal 的 jQuery 版本。
作为参考,这些是我正在使用的脚本。
我的 .info 文件
name = Test
description = A slideshow that implements the PgwSlider Javascript.
core = 7.x
我的 .module 文件
/**
* Implements hook_help().
*
* Displays help and module information.
*
* @param path
* Which path of the site we're using to display help
* @param arg
* Array that holds the current path as returned from arg() function
*/
function test_help($path, $arg) {
switch ($path) {
case "admin/help#pgwslider":
return '<p>' . t("Displays a slideshow") . '</p>';
break;
}
}
function test_init() {
drupal_add_css(drupal_get_path('module', 'test') .'/styles.css');
drupal_add_js(drupal_get_path('module', 'test') .'/test.js');
}
我的 .js 文件
$(document).ready(function() {
$('p').click(function(){
$(this).hide();
});
console.log('test')
});
有什么想法吗?
第二个小问题:
这是包含 js 文件的最佳方式吗?我知道在主题中这是在 .info 文件中完成的,但是对于模块,我没有找到全面的答案。
谢谢大家!
【问题讨论】:
标签: javascript jquery drupal module drupal-7