Radio button causes browser to jump to the top

后端 未结 5 543
甜味超标
甜味超标 2021-02-05 14:48

Problem:

When clicking on a label (for a radio button that has been intentionally hidden by positioning it off-screen), the browser undesirably jumps to the top of the

5条回答
  •  北恋
    北恋 (楼主)
    2021-02-05 15:11

    Interesting. I don't know exactly why it behaves that way, but curing the unwanted behavior is easy: exchange the CSS top and left values of the radio inputs for visibility: hidden.

    Like this:

    
    
    
        
        Demo
        
    
    
        

    "Lorem ipsum" goes here.

    Updated JSFiddle here: http://jsfiddle.net/XkQ7T/1/.

    .
    By the way, setting checked on every radio button is no use - only the last one is actually checked. And it invalidates your code. Also, you need form tags around the group of radio inputs.

提交回复
热议问题