英文:
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>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论