首页 > 解决方案 > 在 MacOS 下拉菜单中移动复选标记

问题描述

<select>我使用and标签创建了一个下拉列表<option>,每次输入新输入时,程序都会创建一个带有 value 属性的新选项标签,以将其添加到下拉列表中的现有选项中。

但是,我的客户使用 MacOS,他想将下拉列表上的复选标记移动到最近添加的选项。复选标记仅在您单击所选行时移动,但在我的情况下,我希望它也移动到最近添加/键入的数据。

这是HTML代码:

<!-- Created select tag so user can access history of talk -->
<div style="top:60px;position:absolute;z-index:2" id="speechBox">
    <!-- The select tag acts like a drop down button, so it passes its value to the input box and not to itself -->
    <select id = 'combo-box' title = "Saved Talk" onchange="document.getElementById('userText').value=this.options[this.selectedIndex].text; document.getElementById('idValue').value=this.options[this.selectedIndex].value;">
  </select>
    <span class = "dropdown" name = "Saved Talk"></span>
    <input id ="userText" name="userText" type="text" onfocus="this.select()" ></input>
    <input name="idValue" id="idValue" type="hidden">
    <button id="speakText" class="toolbutton" title="Speak"></button>
  <hr>
</div>

和 JS:

hiddenArray(); // Access speakArray

// Function containing the speakArray, which saves the recent talk array
function hiddenArray() {
    speakArray = [];
}

function playVoice(language, text) {
  playing = text;

        //Adds option when text is spoken
        var addUserInput = document.createElement("OPTION");
        addUserInput.setAttribute("value", playing);
        addUserInput.text = playing;
        document.getElementById("combo-box").appendChild(addUserInput);

        speakArray.push(playing); // Adds recent talks to speakArray

  if(document.getElementById('mode').innerHTML=="2"){
    //After the voice is loaded, playSound callback is called
    getBotReply(text);
    setTimeout(function(){
        loadVoice(language, playSound);
    }, 4000);
  }
  else{
            loadVoice(language, playSound);
  }
}

标签: javascripthtmlmacos

解决方案


我最终想通了。这是代码:

 hiddenArray(); // Access speakArray

// Function containing the speakArray, which saves the recent talk array
function hiddenArray() {
    speakArray = [];
}

function playVoice(language, text) {
  playing = text;

  //Adds option when text is spoken
  var addUserInput = document.createElement("OPTION");
  addUserInput.setAttribute("value", playing);
  addUserInput.text = playing;
  document.getElementById("combo-box").appendChild(addUserInput);

  document.getElementById("combo-box").value = playing;

  speakArray.push(playing); // Adds recent talks to speakArray

  if(document.getElementById('mode').innerHTML=="2"){
    //After the voice is loaded, playSound callback is called
    getBotReply(text);
    setTimeout(function(){
        loadVoice(language, playSound);
    }, 4000);
  }
  else{
            loadVoice(language, playSound);
  }
}

所以我在这里所做的是将组合框(选择标签)的值分配给最近添加的选项(变量播放)。


推荐阅读