【问题标题】:Issue with Rails, haml + javascript on blur for a field objectsRails 问题,haml + javascript 模糊字段对象
【发布时间】:2012-08-08 08:37:24
【问题描述】:

我正在尝试对特定字段框进行相当简单的模糊选择。我不确定为什么(对于我的例子)我不能简单地让盒子改变模糊动作的背景颜色。

这是我的代码:

在haml html中

:javascript
  $("person_email").blur(function(){
    $("person_email").css("background-color","#D6D6FF");
  });

<input id="person_email" name="person[email]" size="30" type="text" class="MB_focusable">

在html中

<script>
   //<![CDATA[
    $("person_email").blur(function(){
    $("person_email").css("background-color","#D6D6FF");
     });
    //]]>
</script>

【问题讨论】:

    标签: javascript jquery ruby-on-rails haml


    【解决方案1】:

    jQuery 选择器不正确。 如果 selector 是元素的 id,则将 # 放在其名称之前,如果是类,则将 . 放在 jquery 中其名称之前:$('#person_name').(property)

    【讨论】:

      【解决方案2】:

      您应该将# 添加到选择器$("person_email") => $("#person_email")

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-11-23
        • 2012-08-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多