【问题标题】:How do I change form text color?如何更改表单文本颜色?
【发布时间】: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


    【解决方案1】:

    试试

     <%= 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'); "
    

    【讨论】:

    • 不知何故这不起作用,如果我删除“else if”,但它适用于红色
    猜你喜欢
    • 2017-07-06
    • 1970-01-01
    • 1970-01-01
    • 2021-03-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多