可能重复:
如何使用jQuery检查字符串的开头?
我有以下内容:
if ($(this).data('action') == "Editing" || $(this).data('action') == "Create")
{
// how to Check ?
}
Run Code Online (Sandbox Code Playgroud)
如何检查编辑或创建只是第一个单词而不是完整字符串?
Ric*_*lly 10
您可以使用indexOf方法检查第一个匹配项是否位于字符串的开头:
$(this).data('action').indexOf("Editing") == 0
Run Code Online (Sandbox Code Playgroud)
尝试使用正则表达式,如下所示:
var action = $(this).data('action');
var regex = /^(Editing|Create)/i;
if (regex.test(action)) {
// do something
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
17388 次 |
| 最近记录: |