2011-02-08 205 views

回答

10

一个快速的方法来检查,如果字符串包含一个单引号和双引号。

if (str.indexOf('\'') >= 0 && str.indexOf('"') >= 0) { 
    //do something 
} 

编辑:如果字符位于第一个位置,indexOf将返回零。

4

试试这个

var str = "test'\""; 

if((str.IndexOf('\'') > -1) && (str.IndexOf('"') > -1)) 
{ 
    //Code here 
} 

希望这有助于。

2

我猜你想要的东西,像/['||"]/.test(str);

相关问题