如果键入的文本与javascript匹配,如何更改颜色 [英] How do change color if typed text matches javascript
问题描述
Quote:如果键入文本匹配Javascript
如何更改颜色
html代码:
< textarea rows =9cols =100id =textonClick =changeText();>< ; / textarea>
我试过的代码不工作
< pre lang =Javascript> var str = ' 市场跨度>;
var value = str.includes(' 市场'跨度>);
if (value == str){
document .getElementById( text)。style.color = green;
} else {
document .getElementById( text)。style.color = 红色 跨度>;
}
我的尝试:
我有一个文本区域。当我输入一些东西时,有些单词会改变它的颜色。
例如,他去市场买了一个苹果
市场字应变为=绿色苹果字应变为=红色
。 Includes()返回bool;你将它与字符串进行比较......这就是无类型的美丽(我猜)。
String.prototype.includes() - JavaScript | MDN [ ^ ]
Quote:How do Change Color if Typed Text Matches Javascript
html code:
<textarea rows="9" cols="100" id="text" onClick="changeText();"></textarea>
The code I tried not working
var str = 'market';
var value = str.includes('market');
if(value==str) {
document.getElementById("text").style.color ="green";
} else {
document.getElementById("text").style.color ="red";
}
What I have tried:
Quote:I have a Text area. When I type something, some words should change it's color.
for example, He went to the market to buy an apple
the "market" word should become ="green" the "apple" word should become ="red"
.Includes() returns a "bool"; you're comparing it to a "string" ... that's the beauty of "typeless" (I guess).
String.prototype.includes() - JavaScript | MDN[^]
这篇关于如果键入的文本与javascript匹配,如何更改颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!