如何在 drupal 7 中编写一些 jquery 脚本?
How to write some jquery script in drupal 7?
如何在 drupal-7
中编写 jquery
脚本?我的工作站点需要一些 jquery slidetoggle 动画。这是我到目前为止尝试过的:
$(document).ready(function () {
$('div.toggle_area').find('div.toggle_content').hide().end().find('div.toggle_label').click(function() {
$(this).next().slideToggle();
});
});
为此使用 drupal_add_js 函数。
drupal_add_js("jQuery(document).ready(function () {
jQuery('div.toggle_area').find('div.toggle_content').hide().end().find('div.toggle_label').click(function() {
jQuery(this).next().slideToggle();
});
});", 'inline');
手动:
https://api.drupal.org/api/drupal/includes!common.inc/function/drupal_add_js/7
(函数($) {
Drupal.behaviors.YOURTHEMENAME = {
附加:功能(上下文,设置){
/在这里添加你的js代码/
//使用 comm 作为 class 值,因为你想对多个元素进行分组
$('.ticks').click(函数() {
//if you want to hide previously opened comment when a new one is clicked
$('.comments').slideToggle("slow");
});
$('.ticks1').click(function() {
$('.comments1').slideToggle("slow");
});
}
};
})(jQuery);
如何在 drupal-7
中编写 jquery
脚本?我的工作站点需要一些 jquery slidetoggle 动画。这是我到目前为止尝试过的:
$(document).ready(function () {
$('div.toggle_area').find('div.toggle_content').hide().end().find('div.toggle_label').click(function() {
$(this).next().slideToggle();
});
});
为此使用 drupal_add_js 函数。
drupal_add_js("jQuery(document).ready(function () {
jQuery('div.toggle_area').find('div.toggle_content').hide().end().find('div.toggle_label').click(function() {
jQuery(this).next().slideToggle();
});
});", 'inline');
手动:
https://api.drupal.org/api/drupal/includes!common.inc/function/drupal_add_js/7
(函数($) {
Drupal.behaviors.YOURTHEMENAME = {
附加:功能(上下文,设置){
/在这里添加你的js代码/
//使用 comm 作为 class 值,因为你想对多个元素进行分组 $('.ticks').click(函数() {
//if you want to hide previously opened comment when a new one is clicked
$('.comments').slideToggle("slow");
});
$('.ticks1').click(function() {
$('.comments1').slideToggle("slow");
});
}
}; })(jQuery);