我有这段代码:
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
标记是大写还是小写。我怎么能这样做呢?
答案 0 :(得分:2)
像这样使用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";
}
这样条件将两者都比较为大写,即使其中一个是小写的,因此不区分大小写