dojo 如何在js中更新组合框和相应文本框?

nhaq1z21  于 2022-12-08  发布在  Dojo
关注(0)|答案(1)|浏览(195)

我正在尝试更新组合框。如果用户在文本框上输入URL。基于URL,我正在获取一些信息并将该数据推到组合框中
密码:

<body>
<div id="updatecmb">
<div class="Urlwithflds"><input type="text" class="Geturl" placeholder="Layer URL" onchange="Getfields()"><button class="rmvbtn">-</button><br><label for="FeaLayerflds">Select Fields</label><select class="Flds" name="FeaLayerflds"></select> </div>
<div class="Urlwithflds"><input type="text" class="Geturl" placeholder="Layer URL" onchange="Getfields()"><button class="rmvbtn">-</button><br><label for="FeaLayerflds">Select Fields</label><select class="Flds" name="FeaLayerflds"></select> </div>
<div class="Urlwithflds"><input type="text" class="Geturl" placeholder="Layer URL" onchange="Getfields()"><button class="rmvbtn">-</button><br><label for="FeaLayerflds">Select Fields</label><select class="Flds" name="FeaLayerflds"></select> </div>
</div>
<script>
function Getfields(events){
   var txturl=events.target.value;
    // i am fetching the details from url and it gives array
    cmbdata=[1,2,3,4,5,6,7,8];
    selele=events.currentTarget.children[0].children[4]
    cmbdata.forEach(function(entry) {
    selele.add(new Option(entry));
    }
</script>
<body>

我的输入计数增加的基础上,网址,然后查尔兹索引也改变如何更新,如果用户粘贴在第二个文本框只填写第二个选择标签...

qmelpv7a

qmelpv7a1#

在HTML中,传递函数getFields,将this作为其参数,如下所示

<div id="updatecmb">
  <div class="Urlwithflds">
    <input type="text" class="Geturl" placeholder="Layer URL" onchange="getfields(this)">
    <button class="rmvbtn">-</button>
    <br>
    <label for="FeaLayerflds">Select Fields</label>
    <select class="Flds" name="FeaLayerflds">
    </select>
  </div>
  <div class="Urlwithflds">
    <input type="text" class="Geturl" placeholder="Layer URL" onchange="getfields(this)">
    <button class="rmvbtn">-</button>
    <br>
    <label for="FeaLayerflds">Select Fields</label>
    <select class="Flds" name="FeaLayerflds">
    </select>
  </div>
  <div class="Urlwithflds">
    <input type="text" class="Geturl" placeholder="Layer URL" onchange="getfields(this)">
    <button class="rmvbtn">-</button>
    <br>
    <label for="FeaLayerflds">Select Fields</label>
    <select class="Flds" name="FeaLayerflds">
    </select>
  </div>
</div>

然后在函数getFields中我们

function getfields(target){
  const txturl = target.value;
  // assuming we fetched some data from given url as an array
  cmbdata = [1,2,3,4,5,6,7,8];

  // find the element 'select' within the parent element
  selele = target.parentElement.querySelector('select');

  // append each fetched data as new option
  cmbdata.forEach(function(entry) {
    selele.add(new Option(entry));
  });
}

搞定了!
试试看
第一个

相关问题