Drupal 7: How to load js and css files on different pages
What is the best way to load a js a开发者_如何学JAVAnd css file on certain pages (not on every single page like happens when using the .info file)?
Drupal provides two functions: drupal_add_css()
and drupal_add_js()
.
You can use these at any point in your code to add a CSS or JS file to the page load.
If the pages contain a form, you can use something similar to the following code:
$form['#attached']['css'] = array(
drupal_get_path('module', 'ajax_example') . '/ajax_example.css',
);
$form['#attached']['js'] = array(
drupal_get_path('module', 'ajax_example') . '/ajax_example.js',
);
精彩评论