据我所知,这不是一个语法问题(其他 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/