【发布时间】:2023-03-23 23:34:02
【问题描述】:
当我选择input="radio" 时,我想启用/禁用一些checkbox,阅读此post 似乎很容易,但由于什么都不做而无法正常工作,它们始终仍处于禁用状态。我失败了什么?
$("#radio_ruta").on('click', function() {
if ($('#radio_ruta').is(':checked')) {
$(".filtros_mapa").removeAttr("disabled");
} else {
$('.filtros_mapa').checkboxradio('disabled');
//$(".filtros_mapa").attr("disabled", true);
//$(".filtros_mapa").prop("disabled", true);
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="container-fluid">
<div class="row" id="map_section">
<div class="col-2 input" id="filter_container">
<!-- FILTROS-->
<legend>Filtros mapa: </legend>
<label for="radio_ult_pos">Última posición</label>
<input type="radio" name="radio_select" class="filtros_mapa" id="radio_ult_pos">
<label for="radio_ruta">Ruta</label>
<input type="radio" name="radio_select" class="filtros_mapa" id="radio_ruta">
<legend>Filtro datos: </legend>
<label for="checkbox-1">Todos</label>
<input type="checkbox" name="checkbox-1" class="filtros_mapa filtros_mapa_ruta" id="checkbox-1" disabled>
<label for="checkbox-2">tracker 1</label>
<input type="checkbox" name="checkbox-2" class="filtros_mapa filtros_mapa_ruta" id="checkbox-2" disabled>
<label for="checkbox-3">tracker 2</label>
<input type="checkbox" name="checkbox-3" class="filtros_mapa filtros_mapa_ruta" id="checkbox-3" disabled>
<label for="checkbox-4">tracker 3</label>
<input type="checkbox" name="checkbox-4" class="filtros_mapa filtros_mapa_ruta" id="checkbox-4" disabled>
<input type="number" class="form-control filtros_mapa_ruta" id='n_nodes_ruta' value="2" min="1" disabled>
<button type="button" class="btn btn-success" id="filtrar_btn_map">Filtrar</button>
</div>
<!-- MAPA-->
<div class="col-7" id="issMap">
</div>
<!-- INFORMACIÓN -->
<div class="col-3" id="info">
</div>
</div>
</div>
【问题讨论】:
-
我看到你正在使用来自 jQuery UI 的 .checkboxradio 方法,你确定你已经链接了库脚本吗?
-
是的 :) @Jazzpaths
-
嗯,这很奇怪,因为它似乎在 sn-p 中工作,当我运行它时,复选框被禁用,当我点击 Ruta 时,它们被启用。究竟是什么问题?
-
当我在我的程序上执行它时什么都没有发生
-
所以,如果这里可以正常工作而您的程序不能正常工作,那肯定与我们无法在此处访问的程序的其余部分相关。
标签: javascript jquery checkbox