当前位置: 首页 > 知识库问答 >
问题:

如何在jQuery中选择数据标签选项元素?

邢凌
2023-03-14
 <div class="btn-group btn-group-toggle" data-toggle="buttons">
    <label class="btn btn-secondary" for="customRadio1">
    <input type="radio" value="1" name="patient" id="customRadio1" autocomplete="off" > Yes
    </label>
    <label class="btn btn-secondary" for="customRadio2">
    <input type="radio" value="2" name="patient" id="customRadio2" autocomplete="off" > No
    </label>
    </div>

通过添加活动类手动激活

这应该有用,但不行

$("input[name=patient][value='1']").prop("checked",true);

共有1个答案

华修永
2023-03-14

您没有看到结果,因为您没有在正确的位置关闭标记label

null

$("input[name=patient][value='1']").prop("checked", true);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<div class="btn-group btn-group-toggle" data-toggle="buttons">
  <label class="btn btn-secondary" for="customRadio1"></label>
  <input type="radio" value="1" name="patient" id="customRadio1" autocomplete="off"> Yes
  <label class="btn btn-secondary" for="customRadio2"></label>
  <input type="radio" value="2" name="patient" id="customRadio2" autocomplete="off"> No
</div>
 类似资料:
  • 我将html写成 现在我希望如果选项是1,那么它应该被选择为 请帮帮我!!!

  • 我正在Eclipse中执行动态web项目 我在我的jsp页面中使用下拉列表 例如 但我需要为每个选项存储多个值,以便有任何解决方案。。?? 我需要如果用户选择第一个选项,我需要多个选项值 指-- 当用户选择该选项时,我需要4个不同的值,以便有任何解决方案,或者在jsp中有任何替代方案可用于执行该任务。。。??

  • 问题内容: 我正在尝试使用标记在Struts2 jsp中呈现我的列表。 在同一位置,我也使用了标签 标签中已填充数据,而标签中未填充数据。 struts2-jquery-plugin版本:3.7.0 jQuery UI:1.8.2 struts2-json-plugin版本:2.3.16.3 这也被使用: 正常使用struts2 select 标签,可以得到结果 但在同一个JSP,而只是一个内部的

  • 以下代码起作用: 如何将第二行重构为: 您对所选的******选项使用了什么?

  • 但这并不好。我希望标签每秒钟都可见。我想看看有多少标签。然后,如果超过X,只选择一些,但可能有一些更容易。 以下是标签中的代码: 有什么想法吗?

  • 我希望,如果我选择“mammals”,动物选择选项只显示值为1的选项data-animal_class。 我知道如何获得哺乳动物值,但我不知道如何使用过滤器 这是我的代码: