布尔属性的语法是什么?复选框,在HTML中? [英] What is the syntax for boolean attributes, e.g. a checked checkbox, in HTML?

查看:94
本文介绍了布尔属性的语法是什么?复选框,在HTML中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

听起来像一个愚蠢的问题,但我想知道什么是最好的方式说明复选框在HTML中选中/取消选中。

Sounds like a bit of a silly question, but I am wondering what is the best way of stating that a checkbox is checked/unchecked in HTML.

我有看到许多不同的例子:

I have seen many different examples:

<input type="checkbox" checked="checked" />
<input type="checkbox"  />

<input type="checkbox" checked="yes" />
<input type="checkbox" checked="no" />

<input type="checkbox" checked="true" />
<input type="checkbox" checked="false" />

哪些浏览器使用哪些浏览器,最重要的是,jQuery确定哪个框被选中在所有3?

Which browsers work with which ones of these, and most importantly, does jQuery figure out which box is checked in all 3?

编辑:
W3C规范似乎意味着只有那里检查的attr是正确的。

The W3C spec seems to imply that just the checked attr being there is correct. Does that mean that checked="false" and checked="no" will still check the box though?

推荐答案

在HTML中:

<input type="checkbox" checked>
<input type="checkbox" checked="checked">

对于XHTML,您必须使用属性/值匹配对:

For XHTML you have to use attribute/value matching pairs:

<input type="checkbox" checked="checked" />

这篇关于布尔属性的语法是什么?复选框,在HTML中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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