Переместите галочку в выпадающем меню MacOS - PullRequest
0 голосов
/ 26 ноября 2018

Я создал раскрывающийся список с использованием тегов <select> и <option>, где каждый раз, когда вводится новый ввод, программа создает новый тег параметра с атрибутом значения, чтобы добавить его к существующим параметрам в раскрывающемся списке.список.

Однако мой клиент использует 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);
  }
}

1 Ответ

0 голосов
/ 28 ноября 2018

Я понял это в конце.Вот код:

 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);
  }
}

Итак, что я сделал здесь - присвоил значение поля со списком (выбрать тег) недавно добавленной опции (переменная игра).

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...