我正在尝试使用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º 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发布于 2016-11-09 01:36:42
我想这就是你要找的
$('#numero-ficha')[0].parentElement.MaterialTextfield.change("15");
$('#nome-ficha')[0].parentElement.MaterialTextfield.change("some text");https://stackoverflow.com/questions/40498908
复制相似问题