例如,我正在使用以下 JavaScript 来预填充字段,但在单击/取消单击该字段之前不会呈现大纲。我试过了
var doc = document;
doc.getElementById("other-number-tf-ex-input").parentElement.classList.add("mdc-text-field--upgraded");
doc.getElementById("other-number-tf-ex-input").nextElementSibling.classList.add("mdc-text-field__label--float-above");
doc.getElementById("other-number-tf-ex-input").value = values[1].otherPhoneExtensionCode;
window.mdc.autoInit();
HTML是:
<div class="account-telephone-outlined-wrapper">
<div class="mdc-text-field mdc-text-field--outlined mdc-text-field--dense tel-medium" data-mdc-auto-init="MDCTextField">
<input required pattern="^[0-9]*$" type="text" id="cellular-number-tf-cc-input" class="mdc-text-field__input" aria-controls="cellular-number-tf-cc-message">
<label for="cellular-number-tf-cc-input" class="mdc-text-field__label">1</label>
<div class="mdc-text-field__outline">
<svg>
<path class="mdc-text-field__outline-path" d=""/>
</svg>
</div>
<div class="mdc-text-field__idle-outline"></div>
</div>
<p class="mdc-text-field-helper-text mdc-text-field-helper-text--validation-msg" id="cellular-number-tf-cc-message">
00000
</p>
</div>