HTML DOM Label Object
HTML中的HTML DOM标签对象表示
句法
以下是语法-
创建一个
1 | var labelObject = document.createElement("LABEL") |
物产
在此," LabelObject"可以具有以下属性-
| 属性 th> | Description th> |
|---|---|
| Control | 它返回标签的控件 |
| 它返回包含标签的封闭表单的引用 | |
| htmlFor | 它返回/设置 标签的for属性 |
例
让我们来看一个标签htmlForproperty的示例-
现场演示
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | <!DOCTYPE html> <html> <head> Label htmlFor <style> form { width:70%; margin: 0 auto; text-align: center; } * { padding: 2px; margin:5px; } input[type="button"] { border-radius: 10px; } </style> </head> <body> <form> <fieldset> <legend>Label-htmlFor</legend> <label id="CurrentEditor" for="editorTwo">Current Editor:</label> <input type="text" id="editorOne" placeholder="editorOne"> <input type="text" id="editorTwo" placeholder="editorTwo"> <input type="button" onclick="getEventData()" value="Change Editor"> Label for attribute set as editor two </fieldset> </form> var divDisplay = document.getElementById("divDisplay"); var labelSelect = document.getElementById("CurrentEditor"); function getEventData() { if(labelSelect.htmlFor === 'editorTwo'){ divDisplay.textContent = 'Label for attribute set as editor one'; labelSelect.htmlFor = 'editorOne'; } } </body> </html> |
输出量
这将产生以下输出-
在点击"更改编辑器"按钮之前-
点击"更改编辑器"按钮后-