应该如何布尔属性来写的? [英] How should boolean attributes be written?

查看:116
本文介绍了应该如何布尔属性来写的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在阅读有关HTML,XHTML等一些文章在大多数人(即我的preferred语法风格)说,布尔属性应该没有任何值被写入,这样的:

 <输入类型=文本要求>

他们甚至说,这是错误的使用这个属性是这样的:

 <输入类型=文本要求=需要>

一些这方面的文章的链接 W3 它说


  

如果属性为present,其值必须是空字符串或者是属性的规范名称的ASCII不区分大小写的匹配值,没有前导或尾随空格。


但在示例显示是这样的:


  

下面是检查和残疾人复选框的一个例子。该
  检查和残疾人属性是布尔属性。


 <标签><输入类型=复选框选中名称=奶酪禁用>奶酪与LT; /标签>


  

这可以等效写成这样:


 <标签><输入类型=复选框选中=检查名称=奶酪禁用=关闭>奶酪LT; /标签>


  

您也可以混合样式;下面仍然是等效的:


 <标签><输入类型=复选框被查名=禁止奶酪=>奶酪与LT; /标签>

那么,应该如何布尔属性来写的?根据你的经验,选项这是跨浏览器的,哪些不是?


解决方案

没有价值观Attribues在HTML有效的,但在XHTML无效的,因为它不允许出现在XML。也许,这就是你的困惑是来自。那么,哪一个是合法的取决于你的文档的文档类型。

I've been reading some articles about HTML, XHTML, etc. In most of them (i.e. My preferred syntax style) say that boolean attributes should be written without any value, like this:

<input type="text" required>

They even say that it is wrong to use this attributes like this:

<input type="text" required="required">

Some of this articles link W3 which says:

If the attribute is present, its value must either be the empty string or a value that is an ASCII case-insensitive match for the attribute's canonical name, with no leading or trailing whitespace.

but in the examples shows like this:

Here is an example of a checkbox that is checked and disabled. The checked and disabled attributes are the boolean attributes.

<label><input type=checkbox checked name=cheese disabled>Cheese</label>

This could be equivalently written as this:

<label><input type=checkbox checked=checked name=cheese disabled=disabled> Cheese</label>

You can also mix styles; the following is still equivalent:

<label><input type='checkbox' checked name=cheese disabled="">Cheese</label>

So, how should the boolean attributes be written? Based in your experience, which of the options are cross-browser and which are not?

解决方案

Attribues without values are valid in HTML, but invalid in XHTML, because it's not allowed in XML. Perhaps that's where your confusion is coming from. So, which one is valid depends on the doctype of your document.

这篇关于应该如何布尔属性来写的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆