如何避免大小写敏感的返回
how to avoid return of case sensitive
我使用以下代码及其仅用于区分大小写的值,我想要一些如何克服的问题,如果用户使用大写或小写它也会起作用,我该怎么做?
oAc.setFilterFunction(function(sValue, oItem) {
debugger;
var val = (oItem.getText().indexOf(sValue) != -1) || (oItem.getAdditionalText().indexOf(sValue) != -1);
return val;
});
在sValue中,我得到了值,val返回true或false在oItem.getText()中,我得到了要比较的文本,就像我在sValue=I中一样并且oItem.getText()返回索引该方法返回true。
一种简单的方法是在indexOf()
操作之前将两个值转换为小写/大写
oAc.setFilterFunction(function (sValue, oItem) {
debugger;
sValue = sValue.toLowerCase();
var val = (oItem.getText().toLowerCase().indexOf(sValue) != -1) || (oItem.getAdditionalText().toLowerCase().indexOf(sValue) != -1);
return val;
});
另一种解决方案是使用正则表达式来测试值,而不是使用indexOf
if (!RegExp.escape) {
RegExp.escape = function (value) {
return value.replace(/['-'[']{}()*+?.,'''^$|#'s]/g, "''$&")
};
}
oAc.setFilterFunction(function (sValue, oItem) {
debugger;
var regex = new RegExp(RegExp.escape(sValue), 'i');
var val = regex.test(oItem.getText()) || regex.test(oItem.getAdditionalText());
return val;
});
您可以将文本转换为小写。
oAc.setFilterFunction(function(sValue, oItem) {
debugger;
var val = (oItem.getText().toLowerCase().indexOf(sValue.toLowerCase()) != -1) || (oItem.getAdditionalText().toLowerCase().indexOf(sValue.toLowerCase()) != -1);
return val;
})
您可以在名为toLowerCase()或toUpperCase()的String类中查看Java的内置函数
更多信息点击这里
http://docs.oracle.com/javase/7/docs/api/java/lang/String.html
相关文章:
- 节点导出返回一个空对象
- ES6构造函数返回基类的实例
- 监视函数从服务返回不起作用,但作用域函数起作用
- 控制台返回var不是't定义,但它是
- 从函数返回角度承诺
- Javascript返回值只在循环中返回一次
- 从控制器返回后Ajax启动事件激发
- CKFinder 3为所选文件返回错误的URL
- JavaScript Regex(?i)选项中字符串大小写不敏感的部分不起作用
- 正则表达式匹配整个字符串,但大小写不敏感
- 如何避免大小写敏感的返回
- 返回标题大小写,尊重单词中间的大写字母
- document.body.innerHTML只返回最后一个大小写
- JSON Jquery大小写不敏感匹配
- 如何检查特定字符串是否存在于变量中,在javascript中具有大小写敏感和特殊字符
- 简单的大小写不敏感的搜索框的一个表与jQuery
- 将字符串中找到的单词替换为大小写敏感(搜索和高亮显示)
- 非大小写敏感的查询与TaffyDB(或其他JS数据库)
- 使用搜索栏过滤列中有重复条目的区分大小写的数据,并返回特定的行AngularJS
- CodeMirror自动完成:大小写敏感搜索