我有以下mdl-textfield:
<div class="mdl-textfield mdl-js-textfield" id="step_condition">
<textarea class="mdl-textfield__input" type="text" rows="25"> </textarea>
<label class="mdl-textfield__label" for="step_json">Step condition</label>
</div>
若要设置我使用的字段的值,请执行以下操作:
$("#step_condition").get(0).MaterialTextfield.change('100');
我的问题是:
我知道我可以直接从textarea获取值,但是使用API似乎更有意义。
发布于 2015-12-06 20:12:27
您应该向文本区域本身添加一个id,例如:
<div class="mdl-textfield mdl-js-textfield" >
<textarea class="mdl-textfield__input" type="text" rows="25" id="step_json"></textarea>
<label class="mdl-textfield__label" for="step_json">Step condition</label>
</div>
看看官方规范上的例子,在div级别上没有id。http://www.getmdl.io/components/index.html#textfields-section
若要设置字段的值,请执行以下操作
$("#step_json").val("100");
但是,您必须处理标签不会自动移除的事实。这篇文章应该会有所帮助:https://github.com/google/material-design-lite/issues/903
https://stackoverflow.com/questions/34077730
复制相似问题