Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在不使用 jQuery 或任何其他库的情况下,如何在 JavaScriptfor中设置 HTML 元素的属性?<label>
for
<label>
使用htmlFor属性。我认为它的名称有点神秘,因为for它是 JavaScript 中的一个关键字:
htmlFor
var label = document.createElement('label'); label.htmlFor = 'some-input-id';