use*_*347 2 javascript angularjs
我想知道是否有可能知道$ scope中是否有一个字符,例如像这样的字符,但是在angularJs中
$scope.test = "Hi, How Are You?";
if($scope.test.Contains("?")) {
return true
} else {
return false
}
Run Code Online (Sandbox Code Playgroud)
Sho*_*omz 19
您可以替换Contains为match:
if($scope.test.match("?")) {
return true
} else {
return false
}
Run Code Online (Sandbox Code Playgroud)
您甚至可以进一步优化整个代码块:
return !!$scope.test.match("?");
Run Code Online (Sandbox Code Playgroud)
好吧,你可以这样做..
var string = "hello";
alert(string.indexOf("llo") != -1);
Run Code Online (Sandbox Code Playgroud)
所以关于你上面的代码..
$scope.test= "HI How Are You ?";
alert($scope.test.indexOf("How") != -1); // return true;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
45603 次 |
| 最近记录: |