2010-03-19 13 views
1

我有一個子菜單,其中所有項目都鏈接到同一個節點,但具有不同的附加參數,例如:Drupal 6,如何通過url參數識別活動菜單項(完整鏈接)?q = page1&filter = 10

... 
<li...><a href = "/?q=page1&filter=10" class = "... active">Item1</a></li> 
<li...><a href = "/?q=page1&filter=11" class = "... active">Item2</a></li> 
... 

在這種情況下,所有項目都具有「活動」類別,並且它們都沒有類別「活動蹤跡」。

是否有任何方法來確定真正的活動鏈接(爲了造型的目的)?

任何建議將不勝感激!

回答

0

你也可以風格使用Javascript的活動鏈接,但無可否認它是相當冗長。這裏是代碼,您只需將樣式更改爲您想要的樣式即可。

window.onload = kickOff; 

var aAll; 

function kickOff() { 
    aAll = document.getElementsByTagName("a"); 
    // disable and change color of active page's link 
    for (var i=0; i<aAll.length; i++) { 
     if (window.location.href.split("#")[0] == aAll[i].href) { 
      aAll[i].onclick = function() {if (this.blur) {this.blur();} return false;} 
      aAll[i].style.cursor = "text"; 
      aAll[i].style.borderBottom = "none"; 
      aAll[i].style.color = "#FFFFFF"; 
      aAll[i].style.textShadow = "none"; 
      if (aAll[i].className == "site") { 
       aAll[i].style.color = "#ffffff"; 
      } 
      else { 
      aAll[i].style.background = "#a5a9b3 scroll 0pt 100%"; 
      } 
     } 
     // fix ie's lack of support for css :focus so tabbers see skip links on focus 
     if (navigator.appName == "Microsoft Internet Explorer" && aAll[i].className == "skip") { 
      var restoreColor = aAll[i].style.color; 
      var restoreBorder = aAll[i].style.borderBottom; 
      aAll[i].onfocus = function() {this.style.color = "#999999"; this.style.borderBottom = "1px solid #999999";} 
      aAll[i].onblur = function() {this.style.color = restoreColor; this.style.borderBottom = restoreBorder;} 
     } 
    } 
    // fixes in-page link bug for Internet Explorer 
    if (navigator.appName == "Microsoft Internet Explorer") { 
     getElementsByClass("target"); 
    } 
} 

function getElementsByClass(searchClass,node,tag) { 
    // fixes in-page link bug for Internet Explorer; first find all destinations (elements with classname "target"): 
    var classElements = new Array(); 
    if (node == null) { 
      node = document; 
    } 
    if (tag == null) { 
      tag = '*'; 
    } 
    var elAll = node.getElementsByTagName(tag); 
    var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)"); 
    for (var i = 0, j = 0; i < elAll.length; i++) { 
     if (pattern.test(elAll[i].className)) { 
      classElements[j] = elAll[i]; 
      j++; 
     } 
    } 
    // then insert what is an invalid attribute for most elements, with an invalid value to boot: 
    for (var i=0; i<classElements.length; i++) { 
     classElements[i].setAttribute("tabIndex",-1) 
    } 
}