开发者

forward slash in menu stops active link from working - javascript controlled

I'm using a JS to activate the active link within a menu.

Problem is, my CMS places a f开发者_如何学Goorward slash before menu items. As soon as it does this, the JS no longer works. If I remove the slash, it works again.

Any ideas how I get it to work with and without the forward slash?

Here's a page I'm testing it on: http://www.sunseedor...k/products1.php

JS is:

$(function(){ var $page = jQuery.url.attr("file"); $('ul.top-nav li a').each(function(){ var $href = $(this).attr('href'); if ( ($href == $page) || ($href == '') ) { $(this).addClass('on'); } else { $(this).removeClass('on'); } }); });


you might want to try this :

$(function(){
  var currUrl = window.location.href;
   if(currUrl.substr(-1) == "/")
    jQuery.url.setUrl(currUrl.substr(0,currUrl.length-1));

 var $page = jQuery.url.attr("file");   /* this comes as null
                                           if the URL has ending slash*/

 $('ul.top-nav li a').each(function(){
 var $href = $(this).attr('href');
  if ( ($href == $page) || ($href == '') ) {   $(this).addClass('on'); } 
else {
 $(this).removeClass('on');
 } });
 }); 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜