Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/411.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/react-native/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 不区分大小写的java脚本索引_Javascript_Indexof_Case Insensitive - Fatal编程技术网

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())的东西=-谢谢你这工作做得很好谢谢你这工作做得很好不客气谢谢你这工作做得很好不客气