How is it/(or just "is it?") possible to create a Web Component that can be placed inside a form and act just as any input element, that's sent to the server on submit? In other words, can Web Components be used to create custom input elements?

有帮助吗?

解决方案

Use the following browser configuration options before testing:

  • Chrome: about:flags => Enabled Experimental WebKit Features/Enable Experimental Web Platform
  • Firefox: about:config => dom.registercomponents.enabled

to enable document.registerElement.

Use the extends parameter of document.registerElement to extend a native input element:

/* Cross-browser fallback */
document.registerElement = document.registerElement || document.register;
/* Element registration using x-tag format */
var MegaButton = document.registerElement('x-button', {
  prototype: Object.create(HTMLButtonElement.prototype),
  extends: 'button'
  });

References

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top