【发布时间】:2011-09-04 09:18:21
【问题描述】:
我正在尝试在输入特定单词时更改表单字段文本的颜色。如何使用 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'); "
关于如何使其正常工作的任何想法?非常感谢您的帮助!
额外积分:我怎样才能做到这一点,但只改变特定单词的颜色?但是没有别的词了
【问题讨论】:
标签: jquery ruby-on-rails ruby-on-rails-3 jquery-ui onkeydown