检查TextArea/TextBox是否包含某个字符串 [英] Check if TextArea/TextBox contains a certain String
本文介绍了检查TextArea/TextBox是否包含某个字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
鉴于textarea是一个ID为'textareabox'的textarea元素,如何检查其中是否包含字符串?
Given textarea is a textarea element with id 'textareabox', how can I check if it contains a string within it?
var textarea = document.getElementById('textareabox');
var word = something;
if (!textarea.contains(word))
{
textarea.value += word;
}
推荐答案
您可以将 .value
用作:
var textarea = document.getElementById('textareabox');
var word = 'something';
var textValue=textarea.value; //-> don't use .innerHTML since there is no HTML in a textarea element
if (textValue.indexOf(word)!=-1)
{
alert('found')
}
这篇关于检查TextArea/TextBox是否包含某个字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文