版博士V2.0程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

75 lines
2.1 KiB

  1. "use strict";
  2. var __importDefault = (this && this.__importDefault) || function (mod) {
  3. return (mod && mod.__esModule) ? mod : { "default": mod };
  4. };
  5. Object.defineProperty(exports, "__esModule", { value: true });
  6. const HTMLElement_1 = __importDefault(require("../html-element/HTMLElement"));
  7. /**
  8. * HTML Label Element.
  9. *
  10. * Reference:
  11. * https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement.
  12. */
  13. class HTMLLabelElement extends HTMLElement_1.default {
  14. /**
  15. * Returns a string containing the ID of the labeled control. This reflects the "for" attribute.
  16. *
  17. * @returns ID of the labeled control.
  18. */
  19. get htmlFor() {
  20. const htmlFor = this.getAttributeNS(null, 'for');
  21. if (htmlFor !== null) {
  22. return htmlFor;
  23. }
  24. return htmlFor !== null ? htmlFor : '';
  25. }
  26. /**
  27. * Sets a string containing the ID of the labeled control. This reflects the "for" attribute.
  28. *
  29. * @param htmlFor ID of the labeled control.
  30. */
  31. set htmlFor(htmlFor) {
  32. this.setAttributeNS(null, 'for', htmlFor);
  33. }
  34. /**
  35. * Returns an HTML element representing the control with which the label is associated.
  36. *
  37. * @returns Control element.
  38. */
  39. get control() {
  40. const htmlFor = this.htmlFor;
  41. if (htmlFor) {
  42. return this.ownerDocument.getElementById(htmlFor);
  43. }
  44. for (const child of this.children) {
  45. if (child.tagName === 'INPUT') {
  46. return child;
  47. }
  48. }
  49. return null;
  50. }
  51. /**
  52. * Returns the parent form element.
  53. *
  54. * @returns Form.
  55. */
  56. get form() {
  57. let parent = this.parentNode;
  58. while (parent && parent.tagName !== 'FORM') {
  59. parent = parent.parentNode;
  60. }
  61. return parent;
  62. }
  63. /**
  64. * Clones a node.
  65. *
  66. * @override
  67. * @param [deep=false] "true" to clone deep.
  68. * @returns Cloned node.
  69. */
  70. cloneNode(deep = false) {
  71. return super.cloneNode(deep);
  72. }
  73. }
  74. exports.default = HTMLLabelElement;
  75. //# sourceMappingURL=HTMLLabelElement.js.map