使用JQuery动态更改MDL文本字段文本

3

我正在尝试使用JQuery更改MDL文本字段的文本。然而,出现了一些问题,首先标签没有向上动画,对于基本文本字段,占位符文本不会消失。其次,如果将文本字段标记为required,通过JQuery设置它的值后,该字段仍然是红色的,就像没有放置任何内容一样。JSFiddle

HTML:

<dialog id="adicionar-editar-campista" class="mdl-dialog" style="text-align: center">
    <div class="mdl-dialog__content">
        <h4>Ficha de Cadastro</h4>
        <p style="color: red">Campos em vermelho são obrigatórios.</p>

        <form action="#">
            <div id="cadastro-numero-ficha" class="mdl-textfield mdl-js-textfield">
                <input id="numero-ficha" class="mdl-textfield__input" type="text" pattern="-?[0-9]*(\.[0-9]+)?">
                <label class="mdl-textfield__label" for="numero-ficha">N&#186; Ficha</label>
                <span class="mdl-textfield__error">Apenas numeros!</span>
            </div>  

            <div id="cadastro-nome-ficha" class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label">
                <input id="nome-ficha" class="mdl-textfield__input" type="text" required>
                <label class="mdl-textfield__label" for="nome-ficha">Nome Completo</label>
            </div>
        </form>
    </div>
</dialog>

JavaScript:
//Do something
$("#numero-ficha").val(value.number);
$("#nome-ficha").val(value.username);
//Do something
1个回答

11

我认为这就是你在寻找的东西。

$('#numero-ficha')[0].parentElement.MaterialTextfield.change("15");
$('#nome-ficha')[0].parentElement.MaterialTextfield.change("some text");

这里是Fiddle


没错!非常感谢。 - Alexandre Krabbe

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接