0

我需要检查一个字符串是否以http://java脚本开头

我所拥有的是

if(!txt.match(/^http:/)) {}  // this only works for http:

我需要让它为http://

有人可以提出解决方案吗?

4

2 回答 2

2

或者:

txt.substr(0, 7) === "http://"
于 2012-05-22T11:30:23.683 回答
1

你需要转义\字符,也为了检查最好使用test方法。

if(!(/^http:\/\//.test(txt))) {}
于 2012-05-22T11:27:17.120 回答