简体   繁体   English

jQuery本地模拟与远程系统

[英]JQuery local mock vs. remote system

I am afraid I similar question might be already asked somewhere, but I wasn't able to find a solution. 恐怕我已经在某个地方问过类似的问题,但是我找不到解决方案。

Here's roughly my environement + purpose: I have a very simple HTML JQuery Setup whose intent is do collapse the later content when a page has more than 5 h3's. 这大概是我的环境+目的:我有一个非常简单的HTML JQuery Setup,其目的是在页面超过5 h3时折叠以后的内容。 Each h3 is followed by 1 or more paragraphs. 每个h3后跟1个或多个段落。 If a page does have more than 5 h3's every content belonging to the h3 should be automatically collapsed (hidden), shown when the corresponding h3 is clicked and hidden, when clicked again. 如果页面上确实有5个以上的h3,则属于该h3的每个内容都应自动折叠(隐藏),这在单击相应的h3并隐藏后再次显示时会显示。

Here's my jquery code: 这是我的jQuery代码:

$(document).ready(function() {

if ($('h3').length > 4) {
    var headlines = $('h3').slice(3);
    var start = $('h3').slice(3,4);     
    var content = start.nextAll().not('h6');

    headlines.addClass('expandable-headline');
    content.hide(); 

    headlines.click(function() {        
        var successors = $(this).nextUntil('h3');
        successors.toggle();
        $(this).toggleClass('expandable-headline');
    }); 
}
});

Here's my html : 这是我的html

< h3>ABC</h3 >  
< p>some nice content</p >
< h3>ABC</h3>
< p>some nice content</p>
< p>some even nicer content</p>

Last but not least, here's my problem: 最后但并非最不重要的,这是我的问题:

All code above works perfect when run locally in simple test files, but when I try it inside my production system (a Drupal site) it throwns an error at 当在简单的测试文件中本地运行时,以上所有代码都可以完美运行,但是当我在生产系统(Drupal站点)中尝试运行时,它会在

 var successors = $(this).nextUntil('h3');

stating, that $(this).nextUntil is not a function . 说明$(this).nextUntil不是function

Any ideas, what this is about? 有什么想法,这是关于什么的?

I appreciate any help. 感谢您的帮助。
Best Greeets, 最好的问候,
Sunny 晴朗

Is it a versioning problem? 是版本问题吗?

nextUntil was added in v1.4, so if your Drupal system is referencing an older version of jQuery, that'd be the problem. nextUntil是在v1.4中添加的,因此,如果您的Drupal系统引用的是jQuery的较早版本,那就是问题所在。

Are your versions of jQuery the same? 您的jQuery版本是否相同?

To test this, insert this line of code somewhere into your script on each page: 要对此进行测试,请将以下代码行插入每页的脚本中:

alert(jQuery.fn.jquery);

It'll alert() your version number. 它将alert()您的版本号。

If your search the jQuery changelog for nextUntil , you'll see that it was added in version 1.4 , so your Drupal jQuery version might be old. 如果在jQuery changelog中搜索nextUntil ,则会看到它是在1.4版本中添加的,因此您的Drupal jQuery版本可能很旧。

If you are planning on upgrading jQuery (I don't use Drupal. Wordpress works fine for me), this question seems relevant: Drupal 6: best way to upgrade jQuery? 如果您打算升级jQuery(我不使用Drupal。Wordpress对我来说很好用),那么这个问题似乎很重要: Drupal 6:升级jQuery的最佳方法吗? .

Make sure that you aren't including multiple jquery files on the page. 确保页面上没有包含多个jquery文件。 Some drupal modules insert their own jquery libraries into page that they are used on and if they aren't the correct version, the jquery object you are referencing might be overwritten and be the reason why the page isn't working. 一些drupal模块将它们自己的jquery库插入使用它们的页面中,如果它们不是正确的版本,则您引用的jquery对象可能会被覆盖,并且是页面无法正常工作的原因。

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

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