V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐关注
Meteor
JSLint - a JavaScript code quality tool
jsFiddle
D3.js
WebStorm
推荐书目
JavaScript 权威指南第 5 版
Closure: The Definitive Guide
brucmao
V2EX  ›  JavaScript

如何在下拉框中根据 visible text 快速选择一个想要的值

  •  
  •   brucmao · 2022-11-13 18:25:33 +08:00 · 938 次点击
    这是一个创建于 527 天前的主题,其中的信息可能已经有所发展或是发生改变。

    在使用 jira 时想生成一个饼图,这个下拉框中有 300 个值,眼都看花了,怎么快速选择想要的值呢

    网上搜了一下,浏览器控制台中可以使用 value 选择

    document.getElementById("statistictype_select").value = "customfield_10820"; 
    

    但是这样还是不够方便,每次得先控制台找到对应的 value,能不能根据 visible text 快速选择呢,最好模糊匹配,比如我一般记得"项目" 关键字,

    <option value="customfield_11674">项目类型</option>
    <option value="customfield_10820">产品所属项目</option>
    

    有多个相同关键字时可以列出来提供选择

    2 条回复    2022-11-14 17:53:25 +08:00
    leonkfd
        1
    leonkfd  
       2022-11-14 17:49:26 +08:00   ❤️ 1
    ```
    function filterOption(value) {
    const optionsEl = document.querySelectorAll('#statistictype_select option');
    [...optionsEl].map(el => {
    el.style.display = el.innerText.includes(value) ? 'block' : 'none'
    })
    }
    filterOption('项目')
    ```
    brucmao
        2
    brucmao  
    OP
       2022-11-14 17:53:25 +08:00
    @leonkfd 大佬 nb
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1265 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 18:04 · PVG 02:04 · LAX 11:04 · JFK 14:04
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.