How to clear all radio buttons using right click in Javascript?
I would like to clear all radio buttons in a group开发者_高级运维 if I right click on one of them. How can I implement this using Javascript ?
Rather than
Right click an option to deselect: (*) option 1 ( ) option 2 ( ) option 3
which is abusing the user interface, you're better to do this:
( ) none (*) option 1 ( ) option 2 ( ) option 3
Conceptually you can't unselect radio buttons. The point of a radio button group is that at least one needs to be selected. It could actually be considered a bug that it's possible to have a radio button group in which no item is selected.
I suppose you'd have to remove and re-generate the group to clear the selection, exploiting this "bug".
Check out this link at quirksmode on capturing the right mouse click. The combination of an element and a right click should let you uncheck all radio buttons in a given group.
精彩评论