javascript - 在 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);
}
}
解决方案
我最终想通了。这是代码:
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);
}
}
所以我在这里所做的是将组合框(选择标签)的值分配给最近添加的选项(变量播放)。
推荐阅读
- python - 通过 pip install 命令提供的所有软件包的完整列表?
- java - 如何在 hazelcast 配置中添加成员 ip
- axios - 如何解决axios.then回调上的“'response'已定义但从未使用”
- spring - 具有 Unit 返回类型的 Spring Post 方法返回 200 而不是 204
- r - 如何命名循环中的元素?
- javascript - 如何在 Node.JS 代码中的套接字事件之外的范围内使用 let 变量?
- java - Java:此方法必须返回 double 类型的结果类型
- docker - docker代理路径中的nginx到子域
- python - 使用 xpath 获取图像
- python - 我不确定如何将这段代码正确地[使用 PyInstaller] 执行到 .exe 文件中