大佬教程收集整理的这篇文章主要介绍了jquery – Microdata与模块化HTML5中的数据属性,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
<script> $(document).ready(function() { eval($(".wrapper").children("Meta[itemprop=userDoesSomething]").attr("content")); }); </script? <div itemscope class="wrapper" id="module1"> <Meta itemprop="userDoesSomething" content="alert('Microdata is better!');"> Module-specific content </div>
要么
<script> $(document).ready(function() { eval($(".wrapper").data("userDoesSomething")); }); </script> <div class="wrapper" id="module1" data-userDoesSomething="alert('Data attributes are better!');"> Module-specific content </div>
两者都完成了同样的事情,但是使用微数据,我不必在包装器的标签中插入属性.我可以使用元标记在包装器中包含“数据”,保持包装器模板不变.我也意识到数据属性可能更合适,因为微数据实际上是用于类型化数据,但在这种情况下,它更方便.从长远来看,有哪些想法更好?
微数据是“类型数据”的not only.如果您愿意,可以定义自己的Microdata词汇表.但你也可以使用“local”(强调我的):
但是,如果您希望将来在您的网页上使用其他一些Microdata词汇表(例如schema.org),则可能会与您的“本地”微观数据发生冲突.因此,如果它没有为您提供超过data- *属性的好处,我就不会使用Microdata.
关于元元素:您也可以使用data- *属性获得类似的东西.在HTML5,the script
element can be used for “data blocks”中.所以你可以使用类似的东西:
<div class="wrapper" id="module1"> <script type="text/plain" data-userDoesSomething="alert('Data attributes are better!');"> </script> Module-specific content </div> <div class="wrapper" id="module1"> <script type="text/plain" data-userDoesSomething> alert('Data attributes are better!'); </script> Module-specific content </div> <!-- etc. -->
而不是text / plain,你可以使用任何适合你需要的东西(JSON,HTML,……).
以上是大佬教程为你收集整理的jquery – Microdata与模块化HTML5中的数据属性全部内容,希望文章能够帮你解决jquery – Microdata与模块化HTML5中的数据属性所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。