开发者

How do I change form text color?

I'm trying to change my the color of my form field text when a specific word is typed in. How can I use an if else statement to make this work for multiple words?

Current: When 'something' is typed in the color of the text changes to red

 <%= text_field_tag :post, :post, :id => 'posts',
 :onKeyDown => "if (this.value == 'something') (this.style.color = 'red')" %>

What I want to do: (but is not working because I'm a noob at ja开发者_运维知识库vascript syntax)

 <%= text_field_tag :post, :post, :id => 'posts',
 :onKeyDown => "if (this.value == 'something') (this.style.color = 'red') else (this.value == 'stuff')(this.style.color = 'blue'); "

Any ideas on how to make this work correctly? Thank you very much for your help!

Extra Credit: How can I do that but only change the color of that specific word? But no other words


Try

 <%= text_field_tag :post, :post, :id => 'posts',
 :onKeyDown => "if (this.value == 'something') (this.style.color = 'red') else if (this.value == 'stuff')(this.style.color = 'blue'); "
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜