javascript - 禁用 Jquery 中单选列表控件中的单选按钮

标签 javascript jquery radiobuttonlist disabled-input

我必须根据条件禁用给定单选列表控件中的单选按钮。 问题是单选按钮列表是由 CMS 自动生成的,并且所有列表项的 id 都相同。 我如何根据条件应用“禁用”类。 例如 if (some value == am) 然后显示第一个单选按钮并禁用其他两个。

<div class="fieldset">       
 <div class="radio">
            <label >
                <input id="wffmd4800a78bba44322993e9ef2a91e0ea0_Sections_9__Fields_3__Value" name="wffmd4800a78bba44322993e9ef2a91e0ea0.Sections[9].Fields[3].Value" type="radio" value="Morning (8 AM - 1 PM)">
                <span class="disable">Morning (8 AM - 1 PM)</span>
            </label>
        </div>
        <div class="radio">
            <label>
                <input id="wffmd4800a78bba44322993e9ef2a91e0ea0_Sections_9__Fields_3__Value" name="wffmd4800a78bba44322993e9ef2a91e0ea0.Sections[9].Fields[3].Value" type="radio" value=" Afternoon (1 PM - 5 PM)" aria-invalid="false">
                <span> Afternoon (1 PM - 5 PM)</span>
            </label>
        </div>
        <div class="radio">
            <label>
                <input id="wffmd4800a78bba44322993e9ef2a91e0ea0_Sections_9__Fields_3__Value" name="wffmd4800a78bba44322993e9ef2a91e0ea0.Sections[9].Fields[3].Value" type="radio" value=" Evening (5 PM - 9 PM)">
                <span> Evening (5 PM - 9 PM)</span>
            </label>
        </div>
</div>
</div>

最佳答案

这不是一个好主意,但是您可以使用 jquery 通过 value 属性的值选择 radio 并禁用相关 radio (使用 prop 方法) :

$('input[type="radio"][value=" Afternoon (1 PM - 5 PM)"]').prop('disabled', true);
$('input[type="radio"][value=" Evening (5 PM - 9 PM)"]').prop('disabled', true);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="fieldset">       
  <div class="radio">
    <label >
      <input id="wffmd4800a78bba44322993e9ef2a91e0ea0_Sections_9__Fields_3__Value" name="wffmd4800a78bba44322993e9ef2a91e0ea0.Sections[9].Fields[3].Value" type="radio" value="Morning (8 AM - 1 PM)">
      <span class="disable">Morning (8 AM - 1 PM)</span>
    </label>
  </div>
  <div class="radio">
    <label>
      <input id="wffmd4800a78bba44322993e9ef2a91e0ea0_Sections_9__Fields_3__Value" name="wffmd4800a78bba44322993e9ef2a91e0ea0.Sections[9].Fields[3].Value" type="radio" value=" Afternoon (1 PM - 5 PM)" aria-invalid="false">
      <span> Afternoon (1 PM - 5 PM)</span>
    </label>
  </div>
  <div class="radio">
    <label>
      <input id="wffmd4800a78bba44322993e9ef2a91e0ea0_Sections_9__Fields_3__Value" name="wffmd4800a78bba44322993e9ef2a91e0ea0.Sections[9].Fields[3].Value" type="radio" value=" Evening (5 PM - 9 PM)">
      <span> Evening (5 PM - 9 PM)</span>
    </label>
  </div>
</div>

关于javascript - 禁用 Jquery 中单选列表控件中的单选按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41676367/

相关文章:

javascript - 创建动态填充的对象

javascript - 删除 HTML 中的部分标记

javascript - 鼠标行为错误?

asp.net - 3 列布局,当第 1 列和第 3 列为空时,希望中间列拉伸(stretch)得更宽

asp.net - 单选按钮列表布局 ASP .Net

javascript - 垂直居中图像,基于容器高度

javascript - 使用 li :hover is not showing div when the list item is an anchor

javascript - HTML 可编辑表 -> 获取编辑字段

c# - 向radiobuttonlist的单选按钮添加属性

c# - 单选按钮列表未正确选择新值