我有这个代码:
var textarea = document.getElementById('myTextarea');
var tag = '<!DOCTYPE html>';
var textValue = textarea.value;
if (textValue.indexOf(tag) != -1) {
document.getElementById('status').innerHTML = "match found";
} else {
document.getElementById('status').innerHTML = "no match found";
}
我正在尝试获取 indexOf
匹配标签,无论 var
标签是大写还是小写。我怎样才能做到这一点?
最佳答案
像这样使用toUpperCase()
var textarea = document.getElementById('myTextarea');
var tag = '<!DOCTYPE html>';
var textValue=textarea.value;
if (textValue.toUpperCase().indexOf(tag.toUpperCase())!=-1)
{
document.getElementById('status').innerHTML = "match found";
} else {
document.getElementById('status').innerHTML = "no match found";
}
这样,即使其中一个是小写,条件也会将两者比较为大写,因此不区分大小写
关于javascript - javascript indexOf 不区分大小写,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43790802/