簡體   English   中英

使用原型js庫進行Href網址匹配

[英]Href url match using prototype js library

在我的系統中,我正在使用原型js。

現在我想match any href with using href.match and do want something

嘗試完成一些操作,但會產生問題

Suppose: my url 

www.example.com/customer/account/login/an/aaa?333=sddssdsd,sasaas

想要這樣:

如果任何href包含customer/account/login/那么我的條件應該可行。 請在下面嘗試:

   if(accountlink.href.match(/\/customer\/account\/login\//)){
//do someting
}

但這是有條件的,無論何時我都可以工作:

  • www.example.com/customer/account/aaa/
  • www.example.com/aaa/account/login/an/

我不想這樣。

就像href包含customer/account/login/就可以了。

請幫我。

您可以使用香草javascript來做到這一點:

var url = 'www.example.com/customer/account/login/an/aaa?333=sddssdsd,sasaas'
if (url.indexOf('customer/account/login/') > -1) {
  // Do your stuff
}

參考:( http://www.w3schools.com/jsref/jsref_indexof.asp

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM