Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 从父页面向元素添加类_Jquery_Html - Fatal编程技术网

Jquery 从父页面向元素添加类

Jquery 从父页面向元素添加类,jquery,html,Jquery,Html,好的。。我有一些父页面,我们称之为test.html 在该页面内部,我正在加载另外两个外部页面:test1.html和test2.html 使用此脚本: $("#linhas_cat li a").click(function(e) { e.preventDefault(); var current_linha = $(this).attr("class"); var current_link = $(this).attr(

好的。。我有一些父页面,我们称之为test.html

在该页面内部,我正在加载另外两个外部页面:test1.htmltest2.html

使用此脚本:

$("#linhas_cat li a").click(function(e) {
            e.preventDefault();
            var current_linha = $(this).attr("class");
            var current_link = $(this).attr("href");
            var alternate_link = $(this).attr("data-link");

            $('#linhas_cat li a').removeClass('active');

            $("#wrap_linhas_fake ul li").css("background", "#b0aa9d");

            $(this).addClass('active');

            $("#wrap_linhas_fake ul li").filter("." + current_linha).css("background", "#ed1d24");

            $("#container_produto").load(current_link).hide().fadeIn('slow'); //external page test1.html
            $(".conteudo_catalogo").load(alternate_link).hide().fadeIn('slow');//external page test2.html

        });
在页面teste2.html的内部,我有一些菜单。像这样:

<ul class="nome_linhas">
    <li><a href="exibe_linhas.html?sublinha=1">Nome da Linha</a></li>
    <li><a href="exibe_linhas.html?sublinha=2">Nome da Linha</a></li>
    <li><a href="exibe_linhas.html?sublinha=3">Nome da Linha</a></li>
    <li><a href="exibe_linhas.html?sublinha=4">Nome da Linha</a></li>
</ul>
但是,加载页面时,未添加类


如何处理此问题?

。加载有回调,当加载内容时,您可以向链接添加类。哼哼。。。。P如果你还有问题,请告诉我是的,我需要帮助。。不要使用回调,或者我不知道如何使用。是的,我会调试它,并立即开始查找“不工作”错误,给我几个小时。如何打开浏览器的控制台,准确地解释什么是不起作用的呢!呵。。我发现了错误。类“active”正在
LI
中应用,而不是在
a
中。更改此行
$(“.nome\u linhas LI:eq(+idx+”),this)。将class('active')
添加到
$(“.nome\u linhas LI:eq(+idx+”)中。添加类('active')就像一个魅力!很好,很乐意帮忙!
$(".conteudo_catalogo").on('click', '.nome_linhas li a', function(e) {
    e.preventDefault();

    var idx = $(this).closest('li').index();

    $(".conteudo_catalogo").hide().load(this.href, function() {
        $(".nome_linhas li:eq("+idx+")", this).addClass('active')
        $(this).fadeIn('slow');
    });
});
$(".conteudo_catalogo").on('click', '.nome_linhas li a', function(e) {
    e.preventDefault();

    var idx = $(this).closest('li').index();

    $(".conteudo_catalogo").hide().load(this.href, function() {
        $(".nome_linhas li:eq("+idx+")", this).addClass('active')
        $(this).fadeIn('slow');
    });
});