检查url是否有男性,如果是,则将其替换为女性

时间:2017-03-22 07:08:02

标签: javascript jquery

我试图根据男性/女性进行过滤,以便每当我点击男性时,应该通过在网址中找到男性并替换它来将网址更新为女性。

任何帮助都非常感谢。

$('.men').on('click',function(){
var men = location.href;
  if (men.includes("constraint") === false && men.includes("types") === false && men.includes("vendors") === false){ 
       men += "?constraint=men";
  }
  else if(men.includes("constraint=men") === false && men.includes("+men") === false && men.includes("vendors") === false && men.includes("women") === false){
			men += "+men";
//       women.replace("women","men");
  }
  
  else if(men.includes("types") === true && men.includes("=men") === false){
			men += "&constraint=men";  
  }
  
  else if(men.includes("vendors") === true && men.includes("=men") === false){
  			men += "&constraint=men";
  }
    else if(men.includes("men") === true && men.includes("women") === false) {
      		
    	men.replace("women","men");
  }
  
  else if(men.includes("=women") === true || men.includes("+women") === true){
  alert("url contains women");
  }
  else{
    men += "";
  }
  

       
  var men_result = location.href = men;

  document.getElementById("wow").href = men_result;
   
});

1 个答案:

答案 0 :(得分:0)

var href = window.location.href;
if(href.indexOf('men') >= 0 && href.indexOf('women') === -1)
    window.location.href = href.replace('men', 'women');
}