<label>标签你理解了吗?

本文介绍了如何通过HTML中的for属性来优化表单元素的交互体验。主要讲述了for属性的两种使用方式:显示和隐式,并强调了在隐式使用时的注意事项。此外,还展示了如何通过这种方式美化表单元素。

查看了一下W3C:

这里写图片描述

常用for属性用法(W3C):

这里写图片描述

也就是说,可以通过包裹表单的方式使得点击对应的label使得对应的表单聚焦:
这里有显示和隐式两种,但是要注意的是,如果使用隐式,必须里面只有一个对应的表单元素,如果有多个
如下图所示,则点击包裹的非表单元素时只有第一个表单元素会聚焦

这里写图片描述

如下图所示,点击输入值aa只有表单bb会聚焦
这里写图片描述

在项目开发过程中用于常用于美化表单元素

如下图所示

这里写图片描述

html代码:

这里写图片描述

js代码

这里写图片描述

<?xml version="1.0" encoding="utf-8" ?> <Defs> <ThingDef ParentName="BaseMeleeWeapon_Blunt_Quality"> <defName>MeleeWeapon_Mace</defName> <label>mace</label> <description>A refined club, engineered for efficient swinging and deadly impacts.</description> <possessionCount>1</possessionCount> <graphicData> <texPath>Things/Item/Equipment/WeaponMelee/Mace</texPath> <graphicClass>Graphic_Single</graphicClass> </graphicData> <uiIconScale>1.2</uiIconScale> <techLevel>Medieval</techLevel> <costStuffCount>50</costStuffCount> <statBases> <WorkToMake>6000</WorkToMake> <Mass>1.25</Mass> </statBases> <equippedAngleOffset>-65</equippedAngleOffset> <recipeMaker> <researchPrerequisite>Smithing</researchPrerequisite> <skillRequirements> <Crafting>3</Crafting> </skillRequirements> <displayPriority>400</displayPriority> </recipeMaker> <stuffCategories> <li>Metallic</li> <li>Woody</li> </stuffCategories> <weaponTags> <li>MedievalMeleeDecent</li> </weaponTags> <weaponClasses> <li>Melee</li> </weaponClasses> <tools> <li> <label>handle</label> <capacities> <li>Poke</li> </capacities> <power>9</power> <cooldownTime>2</cooldownTime> </li> <li> <label>head</label> <labelUsedInLogging>false</labelUsedInLogging> <capacities> <li>Blunt</li> </capacities> <power>15.7</power> <cooldownTime>2</cooldownTime> </li> </tools> </ThingDef> <ThingDef ParentName="BaseMeleeWeapon_Sharp_Quality"> <defName>MeleeWeapon_Gladius</defName> <label>gladius</label> <description>A short sword of ancient design. Good for stabbing or slashing. It's light and nimble, which sometimes lets it beat bigger, heavier weapons.</description> <possessionCount>1</possessionCount> <graphicData> <texPath>Things/Item/Equipment/WeaponMelee/Gladius</texPath> <graphicClass>Graphic_Single</graphicClass> </graphicData> <uiIconScale>1.2</uiIconScale> <techLevel>Medieval</techLevel> <costStuffCount>50</costStuffCount> <thingSetMakerTags><li>RewardStandardQualitySuper</li></thingSetMakerTags> <weaponTags> <li>MedievalMeleeDecent</li> </weaponTags> <statBases> <WorkToMake>12000</WorkToMake> <Mass>0.85</Mass> </statBases> <relicChance>2</relicChance> <equippedAngleOffset>-65</equippedAngleOffset> <stuffCategories> <li>Metallic</li> <li>Woody</li> </stuffCategories> <tools> <li> <label>handle</label> <capacities> <li>Blunt</li> </capacities> <power>9</power> <cooldownTime>2</cooldownTime> </li> <li> <label>point</label> <capacities> <li>Stab</li> </capacities> <power>16</power> <cooldownTime>2</cooldownTime> </li> <li> <label>edge</label> <capacities> <li>Cut</li> </capacities> <power>16</power> <cooldownTime>2</cooldownTime> </li> </tools> <recipeMaker> <researchPrerequisite>Smithing</researchPrerequisite> <skillRequirements> <Crafting>3</Crafting> </skillRequirements> <displayPriority>410</displayPriority> </recipeMaker> </ThingDef> <ThingDef ParentName="BaseMeleeWeapon_Sharp_Quality"> <defName>MeleeWeapon_LongSword</defName> <label>longsword</label> <description>The ancient weapon of kings, the longsword can be used for slashing or stabbing.</description> <possessionCount>1</possessionCount> <graphicData> <texPath>Things/Item/Equipment/WeaponMelee/LongSword</texPath> <graphicClass>Graphic_Single</graphicClass> </graphicData> <techLevel>Medieval</techLevel> <weaponTags> <li>MedievalMeleeAdvanced</li> <li>LongSword</li> </weaponTags> <costStuffCount>100</costStuffCount> <thingSetMakerTags><li>RewardStandardQualitySuper</li></thingSetMakerTags> <statBases> <WorkToMake>18000</WorkToMake> <Mass>2</Mass> </statBases> <relicChance>2</relicChance> <equippedAngleOffset>-65</equippedAngleOffset> <stuffCategories> <li>Metallic</li> <li>Woody</li> </stuffCategories> <tools> <li> <label>handle</label> <capacities> <li>Blunt</li> </capacities> <power>9</power> <cooldownTime>2</cooldownTime> </li> <li> <label>point</label> <capacities> <li>Stab</li> </capacities> <power>23</power> <cooldownTime>2.6</cooldownTime> </li> <li> <label>edge</label> <capacities> <li>Cut</li> </capacities> <power>23</power> <cooldownTime>2.6</cooldownTime> </li> </tools> <recipeMaker> <researchPrerequisite>LongBlades</researchPrerequisite> <skillRequirements> <Crafting>5</Crafting> </skillRequirements> <displayPriority>420</displayPriority> </recipeMaker> </ThingDef> </Defs>逐行解释
07-19
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值