我正在开发一个自定义的HTML类,可以用作额外的表单类型,支持任何匹配
然而,当扩展一个类时,我发现无法使用伪选择器
简而言之:我想在我的类中添加
[name]
和 [value]
属性的元素。然而,当扩展一个类时,我发现无法使用伪选择器
:invalid
。class HTMLInlineInputElement extends HTMLElement{
constructor(){
super();
this.addEventListener('input', function(event){
this.value = this.innerHTML;
})
}
connectedCallback(){}
get name(){
return this.getAttribute('name');
}
set name(value){
return this.setAttribute('name', value);
}
get value(){
return this.getAttribute('value');
}
set value(value){
return this.setAttribute('value', value);
}
get valid(){
return this.validity.valid;
}
set valid(value){
return this.validity.valid = value;
}
checkValidity(){
if( this.hasAttribute('required') && this.value == null || this.value.length == 0 ){
console.log('req');
this.valid = false;
} else if( this.hasAttribute('pattern') && this.value.match( this.getAttribute('pattern') ) ){
console.log('patt');
this.valid = false;
}
}
}
if( typeof customElements !== 'undefined' ){
customElements.define('inline-form', HTMLInlineFormElement);
customElements.define('inline-input', HTMLInlineInputElement);
} else {
document.createElement('inline-form', HTMLInlineFormElement);
document.createElement('inline-input', HTMLInlineInputElement);
}
简而言之:我想在我的类中添加
HTMLElement.invalid = true;
功能,以便我可以在CSS中使用:invalid
选择器。我该怎么做才能将:is-selectors
添加到我的新类中?