javascript - 使用 CSS 或 Javascript 禁用下拉项
问题描述
我需要禁用、停用或至少隐藏一个名为的下拉项Private request
,我只能使用 CSS 或 Javascript 来执行此操作。
当我检查下拉项目时,它具有 class a.js-dropdown-list
。但是我下拉列表中的每个项目都有这个类。所以我不能只使用{display: none;}
,因为它会隐藏所有选项。下拉列表中的每个项目是否没有更具体的 ID,或者我可以使用 Javascript 停用项目吗?
下拉看起来像这样:
这里的代码(第一个块用于选择器字段,第二个用于下拉菜单):
<div id="js-organization-picker">
<sd-select class="js-share-with-organisation-picker is-private" data-type="link" data-id="customfield_10203" data-value="38" data-options="[{"label":"Private request","styleClass":"is-private","icon":"locked"},{"label":"Share with Testorganisation","value":38,"icon":"unlocked"}]" resolved="">
<a id="js-customfield_10203-dropdown-trigger" class="aui-dropdown2-trigger aui-button aui-button-link js-trigger customfield_10203-trigger select-dropdown-trigger aui-alignment-target aui-alignment-element-attached-top aui-alignment-element-attached-left aui-alignment-target-attached-bottom aui-alignment-target-attached-left active aui-dropdown2-active aui-alignment-enabled" aria-controls="customfield_10203-dropdown" aria-haspopup="true" role="button" tabindex="0" data-aui-trigger="" data-dropdown2-hide-location="js-customfield_10203-dropdown-container" resolved="" aria-expanded="true" href="#customfield_10203-dropdown">
<span class="aui-icon aui-icon-small aui-iconfont-locked">
: : before
</span> Private request
: : after
</a>
<input name="customfield_10203" type="hidden" class="js-input" value="">
<div id="js-customfield_10203-dropdown-container" class="hidden"></div>
</sd-select>
</div>
<div id="customfield_10203-dropdown" class="aui-dropdown2 filter-dropdown aui-style-default js-filter-dropdown select-dropdown aui-layer aui-alignment-element aui-alignment-side-bottom aui-alignment-snap-left aui-alignment-element-attached-top aui-alignment-element-attached-left aui-alignment-target-attached-bottom aui-alignment-target-attached-left aui-alignment-enabled" role="menu" aria-hidden="false" data-id="customfield_10203" resolved="" style="z-index: 3000; top: 0px; left: 0px; position: absolute; transform: translateX(602px) translateY(918px) translateZ(0px);" data-aui-alignment="bottom auto" data-aui-alignment-static="true">
<div role="application">
<ul class="aui-list">
<li>
<a class="js-dropdown-item " href="#">Private request</a>
</li>
<li></li>
<li>
<a class="js-dropdown-item " href="#" data-value="38">Share with Testorganisation</a>
</li>
<li></li>
</ul>
</div>
</div>
解决方案
欢迎!
如果我猜对了,有很多元素具有相同的 ID js-dropdown-list
,并且您想隐藏一个特定的元素,并且该元素没有额外的类,并且您不允许为其添加特异性,比如说添加一个额外的类,您可以执行以下操作:
通过以下方式获取具有此id的所有元素:
let elements = document.querySelectorAll('.js-dropdown-list'); // this is an array of these elements
let elementToHide = elements[n] // whene n is the number of that element
//hiding the element
elementToHide.style.display = 'none';
希望有帮助!
推荐阅读
- r - 如何使用图像作为图例键字形?
- javascript - Jest spy 在不同的目录中不起作用?
- python-3.x - discord.py - 需要帮助才能使用 cog_command_error
- python - rio.plot.show 带彩条?
- np - 为什么所有 NP 完全问题都可以简化为 3-SAT?
- https - “443 端口似乎已关闭”Elastic Beanstalk 负载均衡器
- java - 如何访问没有应用程序 ID 的默认应用程序?
- mysql - 确定用户的新分数是否是他们在特定活动中获得的最佳分数
- c++ - 如何为调用 DirectX 函数的 C# 窗体制作 C++ Dll?
- css - 用于在一个 div 中对齐图标和文本的 flexbox 属性