开发者

how to create label element in javascript

var elem2 = d开发者_StackOverflowocument.createElement("label");
elem2.setAttribute("value","something");
labelView.appendChild(elem2);


Did you add it to the DOM?

Also, a <label> element doesn't make use of the value attribute, it uses innerHTML.

var elem2 = document.createElement('label');
elem2.innerHTML = "something";    
document.getElementsByTagName('body')[0].appendChild(elem2);


you have to add the element to the DOM via appendChild()

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜