這不是一個最好的語法問題(其他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")');
}
}
UPDATE:
<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語句彈出,所以它的考慮前兩個塊是錯誤的......但他們不是。我不明白。但你們快回復!這個網站很棒!
你能後的標記嗎? – 2012-02-18 22:27:11
調試器告訴你什麼?另外,請發佈「鏈接」標記/代碼。 – Steve 2012-02-18 22:27:27
如果您向我們展示您的html,這可能會有所幫助。你已經設置了錯誤的JavaScript調用,因此函數不會被調用。 – 2012-02-18 22:27:58