html5 非空属性,空HTML5数据属性是否有效?(Are empty HTML5 data attributes valid?)

空HTML5数据属性是否有效?(Are empty HTML5 data attributes valid?)

我想编写一个简单的jQuery插件,它在指定的元素下显示内嵌的模态。 我的想法是根据元素上指定的数据属性自动创建脚本。

一个非常基本的例子:

Hover over me for an inline modal!

我只是想知道上述示例中的data-modal-target是否有效,还是必须是data-modal-target="true" ? 我不关心任何比IE9等等的任何东西,我唯一的要求是它是有效的HTML5。

I'd like to write a simple jQuery plugin that displays inline modals under specified elements. My idea is for the script to auto-init based on data attributes specified on elements.

A very basic example:

Hover over me for an inline modal!

I'm just wondering if data-modal-target in the above example is valid, or does it have to be data-modal-target="true"? I don't care about anything crappier than IE9 etc, my only requirement is that it be valid HTML5.

原文:https://stackoverflow.com/questions/9729080

更新时间:2019-11-07 00:33

最满意答案

是的,完全有效。 在你的情况下, data-modal-target将表示一个布尔属性:

2.4.2布尔属性

元素上的布尔属性的存在表示真实值,而不存在该属性则表示false值。

Yes, perfectly valid. In your case, data-modal-target would represent a boolean attribute:

The presence of a boolean attribute on an element represents the true value, and the absence of the attribute represents the false value.

相关问答

是的,完全有效。 在你的情况下, data-modal-target将表示一个布尔属性: 2.4.2布尔属性 元素上的布尔属性的存在表示真实值,而不存在该属性则表示false值。 Yes, perfectly valid. In your case, data-modal-target would represent a boolean attribute: 2.4.2 Boolean attributes The presence of a boolean attribute on an ele

...

我建议您查看Dive Into HTML 5,并决定如果您认为权衡是可以接受的。 据我所知,使用HTML 5没有负面的SEO含义。我刚刚运行w3c验证器在Dive Into HTML 5 ,它自动检测到它是HTML 5并验证它,所以我不认为也将是一个关注。 I'd recommend checking out Dive Into HTML 5 and deciding for yourself if you think the tradeoffs are acceptable. So far as

...

没有真的,他们当然不是100%正确/有效的使用HTML4 .... 但是他们也不会造成问题 ,所以他们仍然是一个很好的方法来解决“我需要一个属性这个问题。 如果它有帮助,我使用这些,同时支持IE6,到目前为止已经有零个问题,我不记得任何一个SO报告任何一个。 There isn't really, they're not 100% correct/valid usage in HTML4 of course....but they don't cause problems either, so t

...

您可以使用getAttribute检索自定义(或您自己的)属性的值。 跟随你的例子

我可以使用data-geoff的值 var geoff = document.getElementById("geoff");

alert(geoff.getAttribute("data-geoff"));

请参阅MSDN 。 虽然在这里提到,您需要IE7才能使其正常工作,我之前曾经使用IE6进行了测试,并且正常运行(甚

...

这是HTML5规范中定义的属性吗? 然后我认为它应该按照你想要的序列化,给出正确的输出方法,例如http://xsltfiddle.liberty-development.net/6qM2e25

a

b

c

被序列化为

a

...

您可以使用相同的标记,但是,您需要使用RoR的帮助程序来获取图像的URL - 您可以使用image_path :

data-pages-bg-image=""

data-bg-overlay="black"

data-overlay-opacity="0.5">

You can u

...

required使用required验证空输入。

Use required in order to not validate empty input.

jQuery的.data()将值存储在内存中,并使用data-*属性进行初始化。 您可能希望通过在元素创建时设置它来坚持下去。 $("

class: "messageToAndFromOtherMember",

"data-bind": "template: { name: 'message-template', data: data }"

}).appendTo("#messageToAndFromOtherMember");

jQuery's .data() st

...

基本上他们建议的是,如果错误消息,状态或数字足够重要,以便呈现给用户,那么它应该以可访问的方式呈现。 WCAG指南1.4.1说: 使用颜色 :颜色不是用于传达信息,指示动作,提示响应或区分视觉元素的唯一可视方式。 (A级) 另外需要注意的是CSS创建的内容不适用于屏幕阅读器和其他辅助技术。 Basically what they're suggesting is that if the error message, status or number is important enough to p

...

始终执行服务器端验证并确认有POST传入。 否则即使是像webcrawler这样简单的事情也会触发空的电子邮件。 <?php

if (empty($_POST['email']) || empty($_POST['name'])) {

// Respond with a proper error message

...

} else {

// Send email

$to = "@yahoo.com";

$name = $_P

...

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值