简体   繁体   English

什么是HTML5标签的替代品 <figure> 和 <section> 在jQuery中使用较旧的浏览器?

[英]What are alternatives to the HTML5 tags <figure> and <section> for older browsers in jQuery?

Can you suggest an HTML5 你能建议HTML5吗

<figure>
    <img src="path/to/image" alt="About image">
    <figcaption>
        <p>This is an image of something interesting.</p>
    </figcaption>
</figure>

and

<section>
    <!-- Content here -->
</section>

tag alternative for older browsers in jQuery? jQuery中旧浏览器的替代标记?

I searched a lot but I found stuffs about the <canvas> tag everywhere. 我进行了很多搜索,但是到处都可以找到有关<canvas>标记的内容。

I will be glad to see your answers, thanks in advance. 我将很高兴看到您的回答,在此先感谢您。

What's jQuery got to do with it? jQuery与它有什么关系? Are you having problems accessing or manipulating HTML5 elements in jQuery? 您在访问或操作jQuery中的HTML5元素时遇到问题吗?

As far as the HTML goes, the new HTML5 tags you've mentioned are all block-level elements that can contain other block-level elements, so the equivalent in HTML4 is <div> : 就HTML而言,您提到的新HTML5标签都是可以包含其他块级元素的所有块级元素,因此HTML4中的等效项是<div>

<div class="figure">
    <img src="path/to/image" alt="About image" />
    <div class="figcaption">
        <p>This is an image of something interesting.</p>
    </div>
</div>

and

<div class="section">
    <!-- Content here -->
</div>

The HTML5 tags should work fine in older browsers and with jQuery, with two exceptions: HTML5标签在较旧的浏览器和jQuery上正常运行,但有两个例外:

  1. Internet Explorer, until version 9, did not support the new tags, as it didn't support any unknown tags. 在版本9之前的Internet Explorer不支持新标签,因为它不支持任何未知标签。 (Their content would be displayed, but the tag itself would not appear in IE's DOM representation of the page.) However, you can make older IEs recognise unknown tags by creating them in JavaScript: see http://remysharp.com/2009/01/07/html5-enabling-script/ (将显示它们的内容,但标签本身不会出现在IE的页面DOM表示中。)但是,您可以通过使用JavaScript创建较旧的IE来识别未知标签:请参阅http://remysharp.com/2009/ 01/07 / html5-enabling-script /

  2. Browsers other than Internet Explorer treat unknown tags as inline, rather than block. 除Internet Explorer之外的浏览器都将未知标记视为内联而不是阻止。 Thus you'll need to assign display: block; 因此,您需要分配display: block; to the block-level HTML5 elements in your stylesheet. 样式表中的块级HTML5元素。 Reset stylesheets like Eric Meyer's often do this. Eric Meyer一样重置样式表经常这样做。

But if you are having any other problems with them, do ask about the problems on Stack Overflow. 但是,如果您在使用它们时还有其他问题,请询问有关Stack Overflow的问题。

There's nothing wrong with using these elements even in older browsers. 即使在较旧的浏览器中使用这些元素也没有错。 The only browser that might give you any trouble, is (obviously) IE, which will not allow styling for any new elements, but there's an easy JavaScript workaround: 唯一可能给您带来麻烦的浏览器是IE,(显然)是IE,它不允许为任何新元素设置样式,但是有一个简单的JavaScript解决方法:

document.createElement("section");
document.createElement("figure");

And so on... 等等...

Other then that, you can absolutely use the new elements easily. 除此之外,您可以绝对轻松地使用新元素。

我建议您使用Modernizr插件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM