为什么浏览器发疯,当我写的东西像< D​​IV /&GT ;? [英] Why does the browser go crazy when I write things like <div/>?

查看:131
本文介绍了为什么浏览器发疯,当我写的东西像< D​​IV /&GT ;?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的意思是,不是< D​​IV /> < D​​IV>< / DIV> 应该是的究竟的同样的事情?

通过浏览器我的意思是最新的Firefox和Internet Explorer。并发疯我的意思是忽略风格包含标签< D​​IV /方式>


解决方案

  

不是< D​​IV /> < D​​IV&GT /; 应该DIV>&LT是完全一样的东西?


只有在XML。你提供你的网页为XML(是application / xhtml + XML )?如果是这样,你可以使用,但你会牺牲IE9之前的IE版本的兼容性。

如果像大多数人一样,你所服务的XHTML页面的text / html ,你必须通过的兼容性指南,其中一个是你必须的只有的使用自结束标记为有一个<$ C $元素C>空缺内容模型,即得。的那些凡在HTML你使用一个标签,没有密切的标签(&LT; IMG&GT; 等)。

否则,你刚刚写什么非XML解析器HTML将看到没有结束标记,这很可能会乱页面的嵌套了一个起始标签。 &LT; D​​IV /方式&gt; 将会把整个页面的其余部分的该div内

I mean, aren't <div/> and <div></div> supposed to be exactly the same thing?

By browser I mean the latest Firefox and Internet Explorer. And by go crazy I mean ignore styles of tags that contain the <div/>.

解决方案

aren't <div/> and <div></div> supposed to be exactly the same thing?

Only in XML. Are you serving your web page as XML (application/xhtml+xml)? If so you can use either, but you'd be sacrificing compatibility with IE versions before IE9.

If like most people you are serving an XHTML page as text/html, you must abide by the compatibility guidelines, one of which is that you must only use self-closing tags for elements that have an EMPTY content model, ie. the ones where in HTML you'd use a single tag with no close-tag (<img> et al).

Otherwise, you've just written what non-XML HTML parsers will see as a start-tag with no end-tag, which is likely to mess the page's nesting up. <div/> will put the whole of the rest of the page inside that div.

这篇关于为什么浏览器发疯,当我写的东西像&LT; D​​IV /&GT ;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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