简体   繁体   English

如何禁用选择框中的特定值之一

[英]How can I disable one of the particular value in selection box

I have a requirement in which I need to show multiple account related to a customer in a dropdown menu. 我有一个要求,我需要在下拉菜单中显示与客户相关的多个帐户。 If the account is not active , I can not able to select it , When I try to select it should show some messages. 如果该帐户未激活,则无法选择它,当我尝试选择该帐户时会显示一些消息。

Do it possible_ 可能吧_

I don't suppose it's this easy? 我不觉得这容易吗?

<select>
  <option value="volvo">Volvo</option>
  <option value="saab" disabled>Saab</option>
  <option value="mercedes">Mercedes</option>
  <option value="audi">Audi</option>
</select>

in which case with jQuery you can use 在这种情况下,您可以使用jQuery

//1.6+
$("option .with-class-you-choose").prop('disabled', true);
//1.5 and below
$("option .with-class-you-choose").attr('disabled','disabled');

Since you tagged Javascript, here's a JS solution for ya. 由于您已标记Javascript,因此这里是针对ya的JS解决方案。

https://jsfiddle.net/scheda/vh7dgenv/ https://jsfiddle.net/scheda/vh7dgenv/

var options = document.getElementsByTagName('option');

for (var i = 0; i < options.length; i++) {
    if (options[i].dataset.enabled == 'false') {
        options[i].disabled = true;
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 一次使用后如何禁用单击/拖动选择框? - How can I disable my click/drag selection box after one use? 如何使用 AngularJS 基于下拉选择值禁用输入文本框? - How can i disable an input text box based on dropdown selection value using AngularJS? 如何在一张幻灯片中针对特定条件禁用 swiper 上的自动播放? - How can I disable autoplay on swiper for a particular condition in one slide? 如何从JavaScript的选择框中获取价值? - How can i get value from selection box in javascript? 根据另一个选择禁用一个选择框 - Disable one Selection Box based on a Selection in another 在多个选择框中删除对特定值的选择 - Remove selection of particular value in multiple select box 如何在选择期间禁用工具提示? - How can I disable tooltips during selection? 如何根据一个选择创建多个动态选择框? - How can I create more than one dynamic select box dependent on one selection? 通过选择一个选择框中的元素,无法选择另一个选择框,即另一个选择框将处于隐藏格式 - By selecting element in one selection Box another selection box can't be selected i.e. another selection box will be in hidden format 如何在建议 selectize.js 之一中禁用自动选择? - How can I disable automatic selection in one of the suggestion selectize.js?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM