空HTML5数据属性是否有效? [英] Are empty HTML5 data attributes valid?

查看:102
本文介绍了空HTML5数据属性是否有效?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想编写一个简单的jQuery插件,在指定的元素下显示内联模式。我的想法是根据元素上指定的数据属性自动初始化脚本。



一个非常基本的例子:

 < p data-modal-target>将鼠标悬停在内嵌模态上!< / p> 

我只是想知道 data-modal-target 在上面的例子中是有效的,还是必须是 data-modal-target =true?我不关心任何比IE9等更棘手的事情,我唯一的要求是它是有效的HTML5。

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


2.4.2布尔属性



元素上存在布尔属性表示真正的
值,缺少属性表示false值。



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:

<p data-modal-target>Hover over me for an inline modal!</p>
<div data-modal-content data-modal-align="right" data-modal-trigger="hover" data-modal-offset="10px"><!-- any desired syntax can go here --></div>

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.

解决方案

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 element represents the true value, and the absence of the attribute represents the false value.

这篇关于空HTML5数据属性是否有效?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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