Check if TextArea/TextBox contains a certain String

前端 未结 3 682
无人共我
无人共我 2020-12-20 08:52

Given textarea is a textarea element with id \'textareabox\', how can I check if it contains a string within it?

var textarea = document.getElementById(\'tex         


        
3条回答
  •  心在旅途
    2020-12-20 09:49

    You could do something like this:

    var textarea = document.getElementById('textareabox').value;
    
    if (texarea.match(word) != null) {
        // do some stuff
    }
    

    A better regex than what I did but I don't know regex all that well (forgive me regex ignorance).

提交回复
热议问题