简体   繁体   English

Javascript代码段无法在Drupal中使用

[英]Javascript code snippet not working in drupal

I'am using the javascript code below to get vertical tabs displayed. 我正在使用下面的javascript代码来显示垂直标签。 In the first line I loaded the jquery library from https://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js . 在第一行中,我从https://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js加载了jquery库。 Then follows the code below. 然后按照下面的代码。 So far so good but I was told by the admin to remove the first line from the content as the library is going to be loaded by drupal autmatically. 到目前为止还算不错,但是管理员告诉我要从内容中删除第一行,因为该库将由drupal自动加载。 Right now the 1.5.2 version is embeded into drupal, I removed the line where I was loading the library externally but my vertical tabs hover effect won't work any more. 现在,1.5.2版本已嵌入到drupal中,我删除了从外部加载库的行,但是垂直选项卡的悬停效果不再起作用。 Any idea why this happened? 知道为什么会这样吗?

$(document).ready(function() {

    $(".tabsnew .tab[id^=tab_menu]").hover(function() {
        var curMenu=$(this);
        $(".tabsnew .tab[id^=tab_menu]").removeClass("selected");
        curMenu.addClass("selected");

        var index=curMenu.attr("id").split("tab_menu_")[1];
        $(".curvedContainer .tabcontent").css("display","none");
        $(".curvedContainer #tab_content_"+index).css("display","block");
    });
});

In Drupal 7 you can't use the $ function anymore (well, not out-of-the-box). 在Drupal 7中,您不能再使用$函数了(嗯,不是现成的)。 The reason is that Drupal allows you to run more than one js library at once and $ is eg also used in prototype. 原因是Drupal允许您一次运行多个js库,并且$也用于原型。

Instead, replace $(document) with jQuery(document) and so on. 而是将$(document)替换$(document) jQuery(document)等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM