我正在尝试在输入特定单词时更改表单字段文本的颜色。如何使用 if else 语句使其适用于多个单词?
当前:当输入“某事”时,文本颜色变为红色
<%= text_field_tag :post, :post, :id => 'posts',
:onKeyDown => "if (this.value == 'something') (this.style.color = 'red')" %>
我想做什么:(但不工作,因为我是 javascript 语法的菜鸟)
<%= text_field_tag :post, :post, :id => 'posts',
:onKeyDown => "if (this.value == 'something') (this.style.color = 'red') else (this.value == 'stuff')(this.style.color = 'blue'); "
关于如何使其正常工作的任何想法?非常感谢您的帮助!
额外的信用:我怎么能做到这一点,但只改变那个特定单词的颜色?但没有别的词