使用polymer的extend属性可以为HTML标签扩展方法,如为:input标签扩展方法如下:
MyInput = Polymer({
is: 'my-input',
extends: 'input',
created: function() {
this.style.border = '1px solid red';
}
});
var el1 = new MyInput();
console.log(el1 instanceof HTMLInputElement); // true
var el2 = document.createElement('input', 'my-input');
console.log(el2 instanceof HTMLInputElement); // true
使用方法:
<input is="my-input">
注意事项:
Note: When using native shadow DOM, extension of native elements can have unexpected behavior and is sometimes not permitted. Test your element with native shadow DOM enabled to catch any problems during development. For information on enabling native shadow DOM, see Global Polymer settings.