使单选按钮无法点击

huangapple go评论88阅读模式
英文:

Making an unclickable radio button

问题

我想要创建一个特定的损坏界面:启用的单选按钮,但不能点击,而是在onClick时执行某些操作。我可以编写onClick函数,但单选按钮总是被选中并保持选中状态。我正在使用ReactJS,但我认为这不会有影响。

我尝试的第一件事:

<input type="radio"/>
<input type="radio"/>
<input type="radio"/>
<input type="radio"/>

但问题是那里可以选择多个按钮,点击按钮会导致选中。我还尝试了:

<input type="radio" disabled/>
<input type="radio" disabled/>
<input type="radio" disabled/>
<input type="radio" disabled/>

但这样按钮看起来是禁用的,无法点击。

我该怎么办?

英文:

I'm looking to create a particular broken interface: enabled radio buttons that cannot be clicked but do some action onClick. I can write the onClick function but the radio button always selects and stays selected. I'm using ReactJS but I don't think that will make a difference.

The first thing I tried:

<input type="radio"/>
<input type="radio"/>
<input type="radio"/>
<input type="radio"/>

But the problem is that multiple buttons are selectable there and clicking a button causes a selection. I also tried

<input type="radio" disabled/>
<input type="radio" disabled/>
<input type="radio" disabled/>
<input type="radio" disabled/>

but then the buttons look disabled, not clickable.

What should I do?

答案1

得分: 1

或:


英文:
<input type="radio" name="foo" value="Foo" onclick="this.checked=false">

or:

<input type="radio" name="foo" value="Foo" onclick="myInput(this)">
<script>
    function myInput(e){
        e.checked = false;
        alert("I'm Clicked!");
    }
</script>

答案2

得分: 0

你可以向HTML输入元素添加 "disabled" 属性以使其无法交互:

英文:

You can add "disabled" attribute to HTML inputs to make them uninteractable:

<input type="radio" disabled>

huangapple
  • 本文由 发表于 2023年6月18日 21:35:21
  • 转载请务必保留本文链接:https://go.coder-hub.com/76500807.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定