繁体   English   中英

JavaScript-检查字符串

[英]JavaScript - Checking string

你好
我想检查当前URL路径的每个单词是否都与我期望的字符串匹配。 当前网址http://www.example.com/category/product/htc-desire

var path = location.pathname;
the path must match every words of "/category/product/htc-desire"

谢谢,我该怎么办。

我认为应该是var path = location.pathname

path.indexOf(pattern) === 0

匹配以模式开头的所有路径。

但是,对于url,您还希望不区分大小写。 在这种情况下:

path.toLowerCase().indexOf(pattern.toLowerCase()) === 0

如果您要完全匹配:

path.toLowerCase() === pattern.toLowerCase()
var path = location.path;
alert("/category/product/htc-desire" === path.replace("http://www.example.com", ""));
//should be true

还是我错过了重点?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM