Javascript 不区分大小写的java脚本索引
我有以下代码:Javascript 不区分大小写的java脚本索引,javascript,indexof,case-insensitive,Javascript,Indexof,Case Insensitive,我有以下代码: 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.g
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";
}
var textarea=document.getElementById('myTextarea');
var标签=“”;
var textValue=textarea.value;
if(textValue.indexOf(标记)!=-1){
document.getElementById('status').innerHTML=“找到匹配项”;
}否则{
document.getElementById('status').innerHTML=“未找到匹配项”;
}
无论var
标记是大写还是小写,我都试图使indexOf
与标记匹配。我该怎么做呢?像这样使用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";
}
var textarea=document.getElementById('myTextarea');
var标签=“”;
var textValue=textarea.value;
if(textValue.toUpperCase().indexOf(tag.toUpperCase())!=-1)
{
document.getElementById('status').innerHTML=“找到匹配项”;
}否则{
document.getElementById('status').innerHTML=“未找到匹配项”;
}
这样,即使其中一个是小写,条件也会将两者作为大写进行比较,因此不区分大小写
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";
}
var textarea=document.getElementById('myTextarea');
var标签=“”;
var textValue=textarea.value;
if(textValue.toUpperCase().indexOf(tag.toUpperCase())!=-1)
{
document.getElementById('status').innerHTML=“找到匹配项”;
}否则{
document.getElementById('status').innerHTML=“未找到匹配项”;
}
这样,即使其中一个是小写,条件也会将两者作为大写进行比较,因此不区分大小写在比较之前,如何将
标记
变量和文本值
变量放在小写位置?将所有内容转换为小写或大写,并保持搜索字符串的大小写相同。类似于textValue.toUpperCase().indexOf(tag.toUpperCase())的东西=-1谢谢,这已经很好地完成了。在比较之前,如何将标记
变量和文本值
变量放在小写?将所有内容转换为小写或大写,并保持搜索字符串的大小写相同。类似于textValue.toUpperCase().indexOf(tag.toUpperCase())的东西=-谢谢你这工作做得很好谢谢你这工作做得很好不客气谢谢你这工作做得很好不客气