html属性值为什么无效,HTML4中是否允许没有值的属性?

布尔属性,是的,它们完全有效.

From W3C:(在SGML和HTML上)

Some attributes play the role of boolean variables (e.g.,the selected

attribute for the OPTION element). Their appearance in the start tag

of an element implies that the value of the attribute is “true”. Their

absence implies a value of “false”.

Boolean attributes may legally take a single value: the name of the

attribute itself (e.g.,selected="selected").

这表明布尔属性在HTML4中也是有效的,但是如果你使用类似的东西,则会无效..因为布尔值属于选项标签..感谢@Ronni Skansing澄清疑问..

Hello

HTML5文档:

空属性语法

Certain attributes may be specified by providing just the attribute

name,with no value.

From W3C:(每晚HTML 5.1)

A number of attributes are boolean attributes. The presence of a

boolean attribute on an element represents the true value,and the

absence of the attribute represents the false value.

section是一个无效的属性,如果你想定义自己的属性,HTML5提供了一种方法来做到这一点..你需要使用data-前缀,例如,你的节应该写成数据节,这样你的属性将是算作有效.

^验证为HTML5

NOTE: Though I provided data- is applicable for HTML5,using custom

attributes in HTML4 is invalid,no matter even if you define data- before the attribute name,but,boolean attributes are valid in HTML4 as well.

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值