Toggle HTML radio button by clicking its label

前端 未结 4 1018
攒了一身酷
攒了一身酷 2020-12-13 01:32

Is there please a simple way to make a radio button toggle - when a text near it is clicked - without introducing any big Javascript Framework into my smal PHP project?

相关标签:
4条回答
  • 2020-12-13 01:47

    You can also wrap your elements without giving them each an ID, since a <label> is implicitly for the input it contains, like this:

    <label>
       <input type="radio" name="mode" value="create">
       <i>create table</i>
    </label>
    
    0 讨论(0)
  • 2020-12-13 01:52

    You can use <label> elements, which are designed to do exactly that:

    <input type="radio" id="radCreateMode" name="mode" value="create" />
    <label for="radCreateMode"><i>create table</i></label>
    
    0 讨论(0)
  • 2020-12-13 01:54

    Wrapping the input under the label should work.

    <label>
        <input type="radio" name="mode" value="create"><i>create table</i>
    </label>
    
    0 讨论(0)
  • 2020-12-13 01:57

    I had trouble finding the value of the radio button using this method, an alternative is to use a hit area increasing clickable area of a button.

    0 讨论(0)
提交回复
热议问题