使用polymer扩展HTML标签

原创
2017/07/02 10:22
阅读数 70

使用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

展开阅读全文
加载中

作者的其它热门文章

打赏
0
0 收藏
分享
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部