Html 使单选按钮可点击链接

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22568679/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 01:19:43  来源:igfitidea点击:

Make Radio Button Clickable Link

htmlcss

提问by Dan Baker

I have a link that holds a radio button, which I want to make a clickable link. I've tried:

我有一个包含单选按钮的链接,我想制作一个可点击的链接。我试过了:

<a href="/">
  <input type="radio" style="pointer-events:none;">
</a>

This prevents anything from happening when I click the radio button. I would like it to follow the link. Any ideas?

这可以防止我单击单选按钮时发生任何事情。我希望它遵循链接。有任何想法吗?

http://css-tricks.com/almanac/properties/p/pointer-events/

http://css-tricks.com/almanac/properties/p/pointer-events/

回答by tvkanters

You can use JavaScript to turn elements like that into a link. E.g.:

您可以使用 JavaScript 将此类元素转换为链接。例如:

<input type="radio" onclick="window.location='/';" />

If other elements should be combined on the link with the radio button, put the onclickattribute on the wrapping element.

如果其他元素应该与单选按钮在链接上组合,请将onclick属性放在包装元素上。

回答by Lil' Bits

Instead of an <a>tag, try surrounding the radio button with a <div>with an onClickevent:

而不是<a>标签,尝试<div>用一个onClick事件包围单选按钮:

<div onClick="window.location = 'http://google.com/';">
    <input type="radio" style="pointer-events:none;"> 
</div>

回答by alessandrio

<input type="radio" onclick="javascript:window.location.href='http://stackoverflow.com'; return false;" />