当通过javascript填充输入框时,使实现标签移出输入框 [英] Make materialize labels move out of input box when input box is filled via javascript

查看:292
本文介绍了当通过javascript填充输入框时,使实现标签移出输入框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通常,使用 Materialize ,文本输入框的标签会显示在输入框中,直到用户输入选择框并输入文本它。但是,当通过javascript填充框的值时,标签不会移动。它保留在框中,并与输入的文本重叠。

Normally, with Materialize, the labels for text input boxes show up inside the input boxes until a user enter selects the box and enters text in it. However, when a box's value is filled via javascript, the label does not move out of the way. It stays in the box and overlaps with the text entered. Is there a way to trigger the label transition with javascript as well, so this doesn't happen?

推荐答案

更具体地说,如果使用JavaScript来触发标签转换,您将在启用涡轮连接的情况下使用Materialise in Rails,您会发现预填充非空值的Materialise表单字段在网页加载时无效。

More specifically, if you are using Materialize in Rails with turbolinks enabled, you will find that Materialize form fields which are prefilled with non-empty values are not active on page load.

以下方法为我工作:

$(function() {
    Materialize.updateTextFields();
});

它将添加类'active'包括相应的标签和前缀图标。

It will add class 'active' to both corresponding labels and prefix icons.

这篇关于当通过javascript填充输入框时,使实现标签移出输入框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆