简体   繁体   English

如何在Web组件中设置div innerHTML

[英]How to set div innerHTML in web Components

html code: html代码:

<div id="scks" is="select-checkbox" url="data.json" displayName="name" displayValue="value">
</div>

js Code: js代码:

// i want to set html to div(#scks)
// it dose not work
// this is the div(#scks)
select_checkbox_proto.createdCallback = function(){
    that.setValue("afterEnd");
}
select_checkbox_proto.setValue = function(val){
    this.innerHTML = val;
}


document.registerElement("select-checkbox",{prototype:select_checkbox_proto,extends: 'div'});

Any one can help me? 有人可以帮助我吗?

1: this is the current div(#scks)? 1:这是当前的div(#scks)? 2: how to set value to div. 2:如何将值设置为div。

your question is not clear for me. 我不清楚您的问题。 if you want to put custom html into div you can use. 如果要将自定义html放到div中,可以使用。

$("#scks").html("your custom html");

and if you want to change attribute for some element you can use attr() or prop() 如果您想更改某些元素的属性,可以使用attr()或prop()

$("#scks").prop('NewAttr', 'NewValue'); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM