0
Follow
0
View

When the drop-down field is selected, the radio button field is cleared. When the field is selected, there is no value

dengap861 注册会员
2023-02-28 06:48
< div class = "md_content_show e397 data - v - 3967" = "" >

thank you!!!!!!

isabel333 注册会员
2023-02-28 06:48

Based on Monster group and GPT:
(using jQuery) :


<select id="select">
  <option value="A">Aoption>
  <option value="B">Boption>
select>
<div id="radio-group" style="display:none;">
  <label><input type="radio" name="radio" value="1">1label>
  <label><input type="radio" name="radio" value="2">2label>
  <label><input type="radio" name="radio" value="3">3label>
div>
<div id="checkbox-group" style="display:none;">
  <label><input type="checkbox" name="checkbox" value="a">alabel>
  <label><input type="checkbox" name="checkbox" value="b">blabel>
  <label><input type="checkbox" name="checkbox" value="c">clabel>
div>


// JavaScript 代码
$(function() {
  // 监听下拉框的变化事件
  $('#select').on('change', function() {
    var selectedValue = $(this).val();
    if (selectedValue === 'A') {
      // 显示栏位二和栏位三
      $('#radio-group').show();
      $('#checkbox-group').show();
    } else if (selectedValue === 'B') {
      // 隐藏栏位二和栏位三,并清空它们的值
      $('#radio-group').hide().find('input').prop('checked', false);
      $('#checkbox-group').hide().find('input').prop('checked', false);
    }
  });
});


About the Author

Question Info

Publish Time
2023-02-28 06:48
Update Time
2023-02-28 06:48