показать / скрыть элемент формы с помощью переключателя

Вы также можете использовать IHtmlHelper.GetEnumSelectList.

    // Summary:
    //     Returns a select list for the given TEnum.
    //
    // Type parameters:
    //   TEnum:
    //     Type to generate a select list for.
    //
    // Returns:
    //     An System.Collections.Generic.IEnumerable`1 containing the select list for the
    //     given TEnum.
    //
    // Exceptions:
    //   T:System.ArgumentException:
    //     Thrown if TEnum is not an System.Enum or if it has a System.FlagsAttribute.
    IEnumerable<SelectListItem> GetEnumSelectList<TEnum>() where TEnum : struct;
0
задан Pierre-Loup Pagniez 29 March 2019 в 11:07
поделиться

2 ответа

Во-первых, имя всех переключателей должно быть одинаковым. Таким образом, он может выбрать по одному. второй div, который вы отображаете, одновременно скрывает другой div.

function show1() {
  document.getElementById('div1').style.display = 'none';
  document.getElementById('div2').style.display = 'none';
}

function show2() {
document.getElementById('div2').style.display = 'none';
  document.getElementById('div1').style.display = 'block';
}

function show3() {
document.getElementById('div1').style.display = 'none';
  document.getElementById('div2').style.display = 'block';
}
body {
  font-family: arial;
}

.hide {
  display: none;
}

p {
  font-weight: bold;
}
<p>Leave</p>
<input type="radio" name="tab" value="igotnone" onclick="show1();" /> Full Day
<input type="radio" name="tab" value="igottwo" onclick="show2();" /> From
<input type="radio" name="tab" value="igottwo" onclick="show3();" /> To

<div id="div1" class="hide">
  <hr>
  <p>From Which Half Session You Are Not Available???</p>
  <input type="radio" value="Yes" name="one"> First Session&nbsp;
  <input type="radio" value="Yes" name="one"> Second Session
</div>

<div id="div2" class="hide">
  <hr>
  <p>To Which Half Session You Are Not Available???</p>
  <input type="radio" value="Yes" name="two"> First Session&nbsp;
  <input type="radio" value="Yes" name="two"> Second Session
</div>

0
ответ дан Anagha 29 March 2019 в 11:07
поделиться

Вы можете заключить две div в одну div и показать / скрыть только это.

Кроме того, переключатели должны иметь одно и то же значение name, чтобы пользователи могли выбирать только один параметр за раз.

function show1() {
  document.getElementById('divs').style.display = 'none';
}

function show2() {
  document.getElementById('divs').style.display = 'block';
}

function show3() {
  document.getElementById('divs').style.display = 'block';
}
body {
  font-family: arial;
}

.hide {
  display: none;
}

p {
  font-weight: bold;
}
<p>Leave</p>
<input type="radio" name="tab" value="igotnone" onclick="show1();" /> Full Day
<input type="radio" name="tab" value="igottwo" onclick="show2();" /> From
<input type="radio" name="tab" value="igottwo" onclick="show3();" /> To

<div id="divs" class="hide">
  <div id="div1">
    <hr>
    <p>From Which Half Session You Are Not Available???</p>
    <input type="radio" value="Yes" name="one"> First Session&nbsp;
    <input type="radio" value="Yes" name="one"> Second Session
  </div>

  <div id="div2">
    <hr>
    <p>To Which Half Session You Are Not Available???</p>
    <input type="radio" value="Yes" name="two"> First Session&nbsp;
    <input type="radio" value="Yes" name="two"> Second Session
  </div>
</div>

0
ответ дан 31piy 29 March 2019 в 11:07
поделиться
Другие вопросы по тегам:

Похожие вопросы: