【问题标题】:In <select> <option> element stays visible after one <option> has been clicked在 <select> 中,<option> 元素在单击一个 <option> 后保持可见
【发布时间】:2021-04-13 19:53:51
【问题描述】:

这是我在 StackOverflow 上的第一个问题,所以如果这个问题有任何问题,请纠正我:

三个元素应根据前一个元素中选择的内容显示元素。

我创建了以下 HTML/Twig 结构

<div class="categorySelector border-two-pixel-solid" id="categorySelector" style="display:block; background: white;">
            {{ _self.cpitems0(categories.categories, categories.categories_info, parts, oop_display, oop_opened) }}
            <select class="categoryElement" id="typDropdown" style="display: block;"> 
            <option class="preselect" value="" style="display: block;">--Please choose an option--</option>
                {{ _self.cpitems1(categories.categories, categories.categories_info, parts, oop_display, oop_opened) }}
            </select>
            <select class="categoryElement" id="geraetDropdown" style="display: block;">
            <option class="preselect" value="" style="display: block;">--Please choose an option--</option>
            {{ _self.cpitems2(categories.categories, categories.categories_info, parts, oop_display, oop_opened) }}
            </select>
    </div>

这个 Twig 宏生成选项(它们由 PHP 控制器提供)

enter image description here

这是显示/隐藏 的 jQuery 代码,为其赋值等等

    $("#typDropdown").children().click(function(e) {
    e.preventDefault();
    e.stopPropagation();

    console.log('before cart clear');
    cart.clearcart();
    console.log('after cart clear');

    $curElTyp = $(this).attr("data-val-two");
    console.log("currentElementValue ", $curElTyp);
    $("#geraetDropdown").show();
    // jQuery selector is only a string
    // All child categories of clicked parent child show / hide
    $("#geraetDropdown").children().not("#" + $curElTyp,).hide();
    $("#geraetDropdown").children("#" + $curElTyp).show();
    $("#geraetDropdown").children(".preselect").show();

    //curElGeraet = $("#geraetDropdown").children("#" + $curElTyp).children('a').attr('data-val-four');
    //console.log('---- curElGeraet ---- ', curElGeraet);
});

单击“上一个”中的一个后,尽管我希望浏览器显示

enter image description here

如何更新元素以使旧文本消失并显示新文本?

【问题讨论】:

  • 你不能隐藏&lt;option&gt;跨浏览器。有些人不支持它。选项是启用/禁用或删除/替换
  • 谢谢!现在我需要找到一种方法来再次添加已删除的

标签: html jquery drop-down-menu twig


【解决方案1】:

我发现了

Set selected option of select box

我只需要将值设置为所需的元素,以便显示它!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-02-09
    • 2014-05-05
    • 2010-10-11
    • 1970-01-01
    • 1970-01-01
    • 2021-10-03
    • 1970-01-01
    相关资源
    最近更新 更多