Show element on radio button selection

后端 未结 3 1383
名媛妹妹
名媛妹妹 2021-01-15 15:05

I would like to show input text field on radio button selection in vanilla JavaScript.

What am I missing?

3条回答
  •  爱一瞬间的悲伤
    2021-01-15 15:30

    You can use event delegation on the fieldset - whenever it observes a bubbled change event, you know that one of the s has been selected, so you can then set the style of the total input field. Use { once: true } so that the listener only gets triggered once:

    const total = document.querySelector('input[name="total"]');
    document.querySelector('fieldset').addEventListener('change', () => {
      total.style.display = "inherit";
    }, { once: true });
    input[name="total"] {
      display: none;
    }
    Choose Size

提交回复
热议问题