1

OK the results of my script aren't exactly producing the answer I am looking and the variable is coming back the opposite of what I am looking for:

//REVISED:This is in the mouseOut of .hover()

Here is my function:

$(".about,.activeAbout").hover(
  function () {
    $('#dropInvestments').css( "left","-9999px" );
    $('#dropMedia').css( "left","-9999px" );
    $('#dropAbout').css( "left","415px" );
    $('#aboutTitle').addClass("aboutTitleActive").removeClass("aboutTitle");
  }, 
      function () {
      $pageLoc = document.location.pathname.split('/about/');
      alert($pageLoc);
      if (document.location.pathname == $pageLoc) 

    {
      $('#aboutTitle').addClass("aboutTitle").removeClass("aboutTitleActive");
    }

}
);

Here is the pathname:

wga/x3/about/history.html

What i want is to only do the class change if the current page is not in the about folder/directory. Any thoughts?

Using split takes out the about and returns the pathname without it...

4

2 回答 2

0

非常感谢 Ohgodwhy 和 TheSmose 为我指明了正确的方向,这就是我如何让它工作的。如果您可以使其更简单或有更好的方式,请随时发布。谢谢你:

$(".about,.activeAbout").hover(
  function () {
    $('#dropInvestments').css( "left","-9999px" );
    $('#dropMedia').css( "left","-9999px" );
    $('#dropAbout').css( "left","415px" );
    $('#aboutTitle').addClass("aboutTitleActive").removeClass("aboutTitle");
  }, 
  function () {
      $pageLoc = document.location.pathname;
      $tarLoc = /about/g;
      $result = $tarLoc.test($pageLoc);
      if ($result !== true) 

    {
      $('#aboutTitle').addClass("aboutTitle").removeClass("aboutTitleActive");
    }

  }
);
于 2012-12-05T03:27:55.120 回答
0

用户正则表达式.test执行此操作:

function () {
    var pattern = /^\/?wga\/x3\/about\/.*/;
    if (pattern.test(document.location.pathname)) {
        $('#aboutTitle').addClass("aboutTitle").removeClass("aboutTitleActive");
    }
}
于 2012-12-05T02:52:08.807 回答