Clear Radio Button

When clicking on a selected radio button, this script will clear it

  1. // Clear Radio Button
  2. // version 0.1 BETA!
  3. // 2006-11-28
  4. // by Jim Biancolo
  5. //
  6. // --------------------------------------------------------------------
  7. //
  8. // This is a Greasemonkey user script.
  9. //
  10. // To install, you need Greasemonkey: http://greasemonkey.mozdev.org/
  11. // Then restart Firefox and revisit this script.
  12. // Under Tools, there will be a new menu item to "Install User Script".
  13. // Accept the default configuration and install.
  14. //
  15. // To uninstall, go to Tools/Manage User Scripts,
  16. // select "Show Cell Headers", and click Uninstall.
  17. //
  18. // --------------------------------------------------------------------
  19. //
  20. // ==UserScript==
  21. // @name Clear Radio Button
  22. // @version 0.1
  23. // @namespace http://www.biancolo.com
  24. // @description When clicking on a selected radio button, this script will clear it
  25. // @include *
  26. // ==/UserScript==
  27.  
  28. (function() {
  29.  
  30. var currRadioRef = null;
  31. var currRadioVal = null;
  32.  
  33. function clearRadio(event) {
  34. var t = event.target;
  35.  
  36. if (isRadio(t)) {
  37. if ((currRadioRef==t) && currRadioVal) {
  38. t.checked = false;
  39. currRadioRef = null;
  40. }
  41. }
  42. }
  43.  
  44. function getRadioState(event) {
  45. var t = event.target;
  46. if (isRadio(t)) {
  47. currRadioRef = t;
  48. currRadioVal = t.checked;
  49. }
  50. }
  51.  
  52. function isRadio(ctrl) {
  53. return (ctrl.tagName.toUpperCase() == "INPUT" && ctrl.type == "radio");
  54. }
  55.  
  56. document.documentElement.addEventListener("mousedown", getRadioState, true);
  57. document.documentElement.addEventListener("click", clearRadio, true);
  58.  
  59. })();
  60.  

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址