html label for查找,HTML Label htmlFor用法及代码示例

DOM标签htmlFor属性用于设置或返回元素的for属性的值。 For属性定义将标记哪个表单元素。

用法:

它用于返回htmlFor属性:labelObject.htmlFor

它用于设置htmlFor属性:labelObject.htmlFor = id

属性值:

id:它定义了应标记元素的id属性。

返回值:它返回一个字符串值,该值表示将被标记的元素的ID。

示例1:演示如何返回属性的HTML程序。

DOM Label htmlFor Property

body {

font-size:20px;

}

GeeksforGeeks

DOM Label htmlfor Property

id="GFG">

Student

name="Occupation"

id="student"

value="student">

Business

name="Occupation"

id="business"

value="business">

Other

name="Occupation"

id="other"

value="other">

Submit

function myGeeks() {

// Return htmlfor property.

var g =

document.getElementById("GFG").htmlFor;

document.getElementById("sudo").innerHTML =

g;

}

输出:

在单击按钮之前:

43ccc20b5d45e8e87eda1841f2e24dd7.png

单击按钮后:

5011363f5588a01dd6dfe1fcfe723802.png

示例2:演示如何设置htmlFor属性的HTML程序。

DOM Label htmlFor Property

body {

font-size:20px;

}

GeeksforGeeks

DOM Label htmlfor Property

id="GFG">

Student

name="Occupation"

id="student"

value="student">

Business

name="Occupation"

id="business"

value="business">

Other

name="Occupation"

id="other"

value="other">

Submit

function myGeeks() {

// Set htmlfor property.

var g =

document.getElementById("GFG").htmlFor =

"Employes"

document.getElementById("sudo").innerHTML =

"The value of the For attribute was "

"changed from student to " + g;

}

输出:

在单击按钮之前:

43ccc20b5d45e8e87eda1841f2e24dd7.png

单击按钮后:

088760bda8f835f86dd470ebe137391a.png

支持的浏览器:下面列出了DOM标签htmlFor Property支持的浏览器:

谷歌浏览器

IE浏览器

Firefox

Opera

Safari

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值