我正在尝试通过将 Javascript (vanilla) 与 Materialize 结合使用来更新选择小部件中的选项。我猜它与“动态生成的选择元素”有关,但我不确定该怎么做?根据Materialise,我可能需要考虑实施:“此外,您将需要单独调用页面生成的任何动态生成的选择元素。” . 不幸的是,我不确定(没有找到)如何“动态生成选择元素”来更新/刷新选择小部件?这是我的相关代码:HTML<!--Let browser know website is optimized for mobile--><meta name="viewport" content="width=device-width, initial-scale=1.0"/><!--Import Google Icon Font--><link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet"><!-- Compiled and minified CSS --><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css"><div class = "container"> <div class="row"> <div class="input-field col s3"> <button id = "btn" class="waves-effect waves-light btn-small"><i class="material-icons left">person_add</i>Add</button> </div> <div class="row"> <div class="input-field col s3"> <button id = "btnRemove" class="waves-effect waves-light btn-small"><i class="material-icons left">delete</i>Remove</button> </div> </div> <!-- CLOSE ROW --> <div class="row"> <div> <div style = "position:relative; top:-10px;" class="input-field col s6"> <select id="voteNoList" onchange="PersonInfo()" required> <option value="">Vote Number?</option> <!-- <?!= currListNo; ?> --> <option value="1">Option 1</option> <option value="2">Option 2</option> <option value="3">Option 3</option> </select> </div> </div> </div> <!-- CLOSE ROW --></div> <!-- CLOSE CONTAINER -->Javascript(原版) //------------ // AUTO //------------ // Select document.addEventListener('DOMContentLoaded', function() { var el = document.querySelectorAll('select'); var instances = M.FormSelect.init(el); }); // Button - Add document.getElementById("btn").addEventListener("click", PersonInfo);
添加回答
举报
0/150
提交
取消