从非HTML5浏览器访问数据标记 [英] Accessing data tag from a non HTML5 browser
问题描述
我是网络领域的总菜鸟,我最近一直在学习jQuery。我担心的是,如果我的浏览器不支持HTML5,我是否可以使用我的HTML中的jQuery访问数据属性?
I'm a total noob in the web arena, I've been learning jQuery lately. My concern is, will I be able to access the 'data' attribute using jQuery from my HTML if my browser does not support HTML5?
推荐答案
是的,您可以使用data属性,即使浏览器不支持HTML5,您也可以使用jQuery访问它:
Yes, you can use the data attribute and you will be able to access it with jQuery even if the browser doesn't support HTML5:
var value = $('#foo').data('value');
你有:
<div id="foo" data-value="bar">Baz</div>
唯一的是数据
属性如果您的DOCTYPE不是HTML5 =>,如果您尝试在HTML 4.01 Transitional中使用它,则无效,例如验证器会哭,但您的网站可以正常运行。
The only thing is that the data
attribute is not valid if your DOCTYPE is not HTML5 => if you try to use it in HTML 4.01 Transitional for example the validator will cry but your site will work without issues.
这篇关于从非HTML5浏览器访问数据标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!