无法在标签中显示dropmenus? [英] Can not show dropmenus in tabs?

查看:123
本文介绍了无法在标签中显示dropmenus?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的JavaScript有问题,我无法正确显示我的标签。

我无法在子标签中显示标签,您有什么问题吗?

I have a problem with my JavaScript, I can't show my tabs properly.
I can't show tabs in sub tabs, do you have any idea what the problem could be?

这是JavaScript代码的一部分(完整的代码在我的 jsfiddle ):

Here's one part of my JavaScript Code (the complete code is in my jsfiddle):

function basla() {

    var tabListItems =  document.getElementById('tabs').children;
    for ( var i = 0; i < tabListItems.length; i++ ) {
        if ( tabListItems[i].nodeName == "LI" ) {
            var tabLink = getFirstChildWithTagName1( tabListItems[i], 'A' );
            var id = getHash1( tabLink.getAttribute('href') );
            tabLinks[id] = tabLink;
            contentDivs[id] = document.getElementById( id );
        }
    }

    var i = 0;

    for ( var id in tabLinks ) {
        tabLinks[id].onclick = showTab1;
        tabLinks[id].onfocus = function() { this.blur(); };
        if ( i == 0 ) tabLinks[id].className = 'selected';
        i++;
    }

    var i = 0;

    for ( var id in contentDivs ) {
        if ( i != 0 ) contentDivs[id].className = 'tabIcerik hide';
        i++;
    }
}


推荐答案

只选择标签元素的直接子项。你想要的是后代(包括嵌套元素):

You are only selecting direct children of your tabs element. What you want are descendants (that includes nested elements):

var tabListItems =  document.getElementById('tabs').getElementsByTagName('*');

这会在ID <$ c $的元素中选择所有 c> tabs (包括嵌套的 li ),而不只是第一个和第二个 li 以及 ul

This will select all elements inside the element with ID tabs (including the nested lis) and not just the first and second li as well as the ul.

您的子标签 li 的空标识符。在你的循环中,它会尝试设置 tabLinks [] ,这当然是不可能的,当它到达那个元素时,会破坏循环的其余部分。您需要捕获该情况并将其排除:

The next problem is your empty id for the subtab li. In your loop, it will attempt to set tabLinks[""], which of course is impossible and will break the rest of the loop when it gets to that element. You need to catch that case and exclude it:

var id = getHash1( tabLink.getAttribute('href') );
if (id=="") continue;






最后,开始,在选择任何选项卡之前。这是因为没有为第一个 li 设置类 tabIcerik ,除非您切换到另一个元素,它。您应该预先设置它,或者在循环的最后中更改以下行。


And, lastly, you have a display error at the start, before any tab is selected. That is due to the class tabIcerik not being set for the first li unless you switch to another element and then back to it. You should either set it upfront or change the following line in the last for loop.

if ( i != 0 ) {contentDivs[id].className = 'tabIcerik hide';}
else {contentDivs[id].className = 'tabIcerik';}

这篇关于无法在标签中显示dropmenus?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆