【问题标题】:Select options multiple not work in desktop选择多个选项在桌面上不起作用
【发布时间】:2021-06-11 15:05:53
【问题描述】:

删除这个问题请删除

【问题讨论】:

  • 请给出您期望的输出和当前输出的截图。另外,显示一些代码。我们无法在不知道问题的情况下为您提供帮助。
  • 用于选择多个选项的 Windows UI 是在您选择它们​​时按住控件。它不会将它们呈现为复选框。
  • <select><option> 无法以这种方式修改,您需要使用替代元素并将它们设置为类似的样式、使用插件或使用 Webcomponents API。跨度>
  • 所以使用它们。只需按照标准的 Windows 方式使用 UI,而不是期望它看起来像 Android。

标签: html


【解决方案1】:

this link 已经回答了您想做的事情。为了您的方便,我提供了 jsfiddle。

var expanded = false;

function showCheckboxes() {
  var checkboxes = document.getElementById("checkboxes");
  if (!expanded) {
    checkboxes.style.display = "block";
    expanded = true;
  } else {
    checkboxes.style.display = "none";
    expanded = false;
  }
}
.multiselect {
  width: 200px;
}

.selectBox {
  position: relative;
}

.selectBox select {
  width: 100%;
  font-weight: bold;
}

.overSelect {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
}

#checkboxes {
  display: none;
  border: 1px #dadada solid;
}

#checkboxes label {
  display: block;
}

#checkboxes label:hover {
  background-color: #1e90ff;
}
<form>
  <div class="multiselect">
    <div class="selectBox" onclick="showCheckboxes()">
      <select>
        <option>Select an option</option>
      </select>
      <div class="overSelect"></div>
    </div>
    <div id="checkboxes">
      <label for="one">
        <input type="checkbox" id="one" />First checkbox</label>
      <label for="two">
        <input type="checkbox" id="two" />Second checkbox</label>
      <label for="three">
        <input type="checkbox" id="three" />Third checkbox</label>
    </div>
  </div>
</form>

【讨论】:

  • 在此代码示例中,我尝试使用checkbox 解决您对multiple select 的查询。现在你要问的是下一步。请对将所选选项存储在value[] 中的下一步进行少量研究。 stackoverflow.com 太棒了。你会得到你的答案。我不告诉你,因为那样你就学不会了。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-05-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-05-01
  • 1970-01-01
  • 2013-08-08
相关资源
最近更新 更多