我正在尝试第一次使用html创建customElement,但getElementsByName无法正常工作
首先我上课
class LineDiv extends HTMLDivElement{ //to automatically always have only one blank line and it is at the end
constructor(){
super(); //execute constructor of prototype that was extended
alert('here');//constructor fires successfully
}
//我在这两行中注册一个自定义元素
let customElementRegistry=window.customeElements;
customElements.define('line-div',LineDiv,{extends: 'div'}); //register a new custome element, line-div is element name LineDiv is class as defined in code and 3rd arg is what element it extends (inherits from)
//然后我创建一个新的customElement构造函数成功触发
var ProtoDiv=document.createElement("div",{is:'line-div'}); //my custom element inheriting div
var textBox=document.createElement('input');
textBox.type='text';
ProtoDiv.appendChild(textBox);
ProtoDiv.name='test_line[]';
ProtoDiv.id='test_line_0'
document.body.appendChild(ProtoDiv);
//因此div和文本框已成功添加到文档中,并且文本框在屏幕上可见
alert(document.getElementsByBame('line-div[]').length);//Always returns 0
getElementsByTagName
: