php - 为什么当我单击调用此函数的链接时没有任何反应?

标签 php javascript

据我所知,这不是一个语法问题(其他 JS 函数调用在同一页面上工作得很好)。

它询问的第一个问题是特定 DIV id 的显示属性是否设置为“无”(确实如此),如果是这样,则应将其设置为“阻止”(以及其他一些内容) ,但绝对没有任何反应。我为另一个站点编写了该函数,它在那里运行得很好,但现在......什么也没有。我要拔头发了!提前致谢...

        function showHideFooter(FooterLinkP,FooterLinkSPAN)
        {   
            var DIV = document.getElementById('FooterLinksContentDIV');
            var P = document.getElementById(FooterLinkP);
            var SPAN = document.getElementById(FooterLinkSPAN);

            if (DIV.style.display == 'none')
            {
                DIV.style.display = 'block';
                P.style.display = 'block';
                SPAN.style.border = '1px solid #606060;';
                SPAN.setAttribute('style','background: url("img/navlinkhoverbg.jpg")');
            }
            else if ((DIV.style.display == 'block') && (SPAN.style.border !== 'transparent'))
            {
                P.style.display = 'none';
                DIV.style.display = 'none';
                SPAN.style.background = 'transparent';
                SPAN.style.border = 'transparent';
                SPAN.setAttribute('style','background:hover:url("img/navlinkhoverbg.jpg")');
                SPAN.setAttribute('style','border:hover: 1px solid #606060;');
            }
            else
            {
                var number = 1;

                var contentArray = new Array();
                contentArray[0] = '<? echo METHODS::footerPopulator(1,'title');?>';
                contentArray[1] = '<? echo METHODS::footerPopulator(2,'title');?>';         
                contentArray[2] = '<? echo METHODS::footerPopulator(3,'title');?>';
                contentArray[3] = '<? echo METHODS::footerPopulator(4,'title');?>';
                contentArray[4] = '<? echo METHODS::footerPopulator(5,'title');?>';
                contentArray[5] = '<? echo METHODS::footerPopulator(6,'title');?>';
                contentArray[6] = '<? echo METHODS::footerPopulator(7,'title');?>';
                contentArray[7] = '<? echo METHODS::footerPopulator(8,'title');?>';
                contentArray[8] = '<? echo METHODS::footerPopulator(9,'title');?>';

                for (section in contentArray)
                {
                    document.getElementById(contentArray[section]).style.display = 'none';

                    while (number <= 9)
                    {
                        document.getElementById(number).style.background = 'transparent';
                        document.getElementById(number).style.border = 'transparent';
                        document.getElementById(number).setAttribute('style','background:hover:url("img/navlinkhoverbg.jpg")');
                        document.getElementById(number).setAttribute('style','border:hover: 1px solid #606060;');
                        number++;
                    }   
                }
                P.style.display = 'block';
                SPAN.style.border = '1px solid #606060;';
                SPAN.setAttribute('style','background:url("img/navlinkhoverbg.jpg")');
            }
        }

更新:

<SPAN class="FooterLinkSPAN" id="1">
<A href="#links" onclick="showHideFooter('<? echo METHODS::footerPopulator(1,'title'); ?>','1');" class="footerLinks"><? echo METHODS::footerPopulator(1,'title');?></A>
</SPAN>

放置在 if 和 else if 语句中的警报不会产生任何结果,但放置在 else 语句中的警报会弹出,因此它认为前两个 block 是假的......但它们不是。我不明白。不过你们回答得快啊!这个网站太棒了!

最佳答案

您可能在 CSS 中设置了 display:none,而不是在元素上内联。如果只是在 CSS 中,DIV.style.display 将为 "" 而不是 "none"

如果是这种情况,请将第一个 if() 语句更改为此...

if (!DIV.style.display || DIV.style.display == 'none')
        {

关于php - 为什么当我单击调用此函数的链接时没有任何反应?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9344720/

相关文章:

php - Doctrine 仅保留 CollectionType 中的最后一个实体

php - 编写连接 4 个表的 mysql 查询时遇到问题

javascript - AngularJS - 使用 ui-router 时, View 在重新出现之前不会被清理

javascript - jquery 简单的点击事件

javascript - 在函数/promise 范围之外使用对象

php - 如何使用包含的 php 文件的结果作为查询参数

php - <hr> html 标签的小问题

php - 某些产品是购物车 woocommerce 中的单一产品

javascript - 根据 map 的缩放级别和点击显示多边形图层

javascript - 接收由 jQuery 发送并由 Node Js 接收的 JSON 形式的数组表单数据