gpt4 book ai didi

javascript - 如何在 Jquery 中禁用输入(单选)按钮中的类

转载 作者:行者123 更新时间:2023-12-03 00:06:13 25 4
gpt4 key购买 nike

我需要使用 qusweitstnesel 类名称禁用 KG 值单选按钮。这是我的代码

HTML

<li id="field_1_48" class="gfield qusweitstnesel gfield_contains_required field_sublabel_below field_description_below gfield_visibility_visible" style="display: list-item;">
<label class="gfield_label">Weight<span class="gfield_required">*</span></label>
<div class="ginput_container ginput_container_radio">
<ul class="gfield_radio" id="input_1_48">
<li class="gchoice_1_48_0">
<input name="input_48" value="KG" id="choice_1_48_0" tabindex="13" disabled="disabled" class="gf-default-disabled" type="radio">
<label for="choice_1_48_0" id="label_1_48_0">KG</label>
</li>
<li class="gchoice_1_48_1">
<input name="input_48" value="Stone" checked="checked" id="choice_1_48_1" tabindex="14" type="radio">
<label for="choice_1_48_1" id="label_1_48_1">Stone</label>
</li>
</ul>
</div>
</li>

JQuery:

var kgs="KG";
jQuery(".qusweitnotsel .ginput_container_radio .gfield_radio li input[type=radio][value='+ kgs +']").attr("disabled","disabled");

最佳答案

您必须在 [value='"+ kgs +"'] 中的单引号内使用双引号。

请注意:您已经在 HTML 中为单选按钮设置了禁用属性。您在代码中使用的类名也有拼写错误,如 qusweitnotsel....应该是 qusweitstnesel

var kgs="KG";
jQuery(".qusweitstnesel .ginput_container_radio .gfield_radio li input[type=radio][value='"+ kgs +"']").attr("disabled","disabled");
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>


<li id="field_1_48" class="gfield qusweitstnesel gfield_contains_required field_sublabel_below field_description_below gfield_visibility_visible" style="display: list-item;">
<label class="gfield_label">Weight<span class="gfield_required">*</span></label>
<div class="ginput_container ginput_container_radio">
<ul class="gfield_radio" id="input_1_48">
<li class="gchoice_1_48_0">
<input name="input_48" value="KG" id="choice_1_48_0" tabindex="13" class="gf-default-disabled" type="radio">
<label for="choice_1_48_0" id="label_1_48_0">KG</label>
</li>
<li class="gchoice_1_48_1">
<input name="input_48" value="Stone" checked="checked" id="choice_1_48_1" tabindex="14" type="radio">
<label for="choice_1_48_1" id="label_1_48_1">Stone</label>
</li>
</ul>
</div>
</li>

您还可以使用Template Literals允许嵌入表达式:

var kgs="KG";
jQuery(`.qusweitstnesel .ginput_container_radio .gfield_radio li input[type=radio][value=${kgs}]`).attr("disabled","disabled");
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>


<li id="field_1_48" class="gfield qusweitstnesel gfield_contains_required field_sublabel_below field_description_below gfield_visibility_visible" style="display: list-item;">
<label class="gfield_label">Weight<span class="gfield_required">*</span></label>
<div class="ginput_container ginput_container_radio">
<ul class="gfield_radio" id="input_1_48">
<li class="gchoice_1_48_0">
<input name="input_48" value="KG" id="choice_1_48_0" tabindex="13" class="gf-default-disabled" type="radio">
<label for="choice_1_48_0" id="label_1_48_0">KG</label>
</li>
<li class="gchoice_1_48_1">
<input name="input_48" value="Stone" checked="checked" id="choice_1_48_1" tabindex="14" type="radio">
<label for="choice_1_48_1" id="label_1_48_1">Stone</label>
</li>
</ul>
</div>
</li>

关于javascript - 如何在 Jquery 中禁用输入(单选)按钮中的类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54957680/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com