Rails ERB文本/密码字段工具提示的焦点

Rails ERB Text/Password field tooltip on focus

本文关键字:工具提示 焦点 字段 密码 ERB 文本 Rails      更新时间:2023-09-26

我有一个密码重置表单,用户必须在其中输入密码和密码确认字段。

<div class="field">
  <%= f.password_field :password_confirmation,
      required: true,
      placeholder: 'Password Confirmation',
      class: 'ctrl',
      title: "should match password" %>
</div>

我知道因为这是一个文本字段,所以我不能使用"rel"属性。

如果我用

来显示它
$(function(){
  $("[rel='nofollow']").tooltip();
});

并在

字段中添加这些属性:
:data => {:toggle=>"tooltip"},
'data-original-title' => "should match password",
'data-placement' => 'right',
rel: 'nofollow'

它只会以一种难看的方式显示标题,而不是作为工具提示。

如何在焦点上显示字段的标题?

可以在初始化时将工具提示的触发器属性设置为focus:

  $('.text-tooltip').tooltip({
    trigger: 'focus'
  });

text-tooltip类添加到输入,它应该触发焦点,拾取元素的title属性作为工具提示文本。