<!-- -->在 html 中的意思是 [英] What does <!-- --> In html mean

查看:49
本文介绍了<!-- -->在 html 中的意思是的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以在 html 中你经常看到

So in html you frequently see

<!-- HTML TEXT HERE -->

大于感叹号双连字符和小于双连字符的目的是什么?

What is the purpose of Greater than exclamation mark double hyphens and double hyphen less than ?

推荐答案

这些是评论,对用户不可见,但仅在您查看实际 HTML 时可见.

These are comments, that are not visible to the user but only when you view the actual HTML.

它们在您进行测试时注释掉代码块也很有用,这样您就可以避免必须将代码剪切并粘贴到其他地方,然后再将它们复制回来.

They are also useful in commenting out a block of code when you're doing testing, that way you can prevent from having to cut and paste the code else where, and then copy them back.

此外,一些开发人员使用它们来隐藏"代码(通常在脚本中),以避免为禁用 Javascript 的浏览器显示大量代码.

Additionally, some developers used them to 'hide' code, usually in scripts, to avoid a chunk of code displayed for browsers that disable Javascript.

<script>
<!--
function displayMsg() {
    alert("Hello World!")
}
//-->
</script> 

这将阻止从 function ....} 的代码显示在禁用 Javascript 的浏览器上.您还会经常看到标签.

That will prevent code from function .... to } from showing up on browsers that have Javascript disabled. You'll also frequently see tags.

它还用于条件注释,它仅在 Internet Explorer 中受支持,您可以借此使 HTML 适应 IE6 等传统浏览器,这样您的闪亮网站就不会在旧浏览器上崩溃.查看此处了解更多信息.

It is also used for conditional comments, which are only supported in Internet Explorer, whereby you adapt your HTML to legacy browsers like IE6, so your shiny website doesn't break on old browsers. See here for more info.

以下是您可能会看到的条件注释示例:

Here's an example of conditional comments you might see:

<!--[if lte IE 8]><link rel="stylesheet" href="css/ie/v8.css" /><![endif]-->

这意味着如果 Internet Explorer 是版本 8(旧的和过时的),则加载该样式表.

That means if Internet Explorer is Version 8 (old and outdated) load that stylesheet.

有关评论的更多信息,这是一个很好的教程.

For more information about comments, this is a good tutorial.

这篇关于&lt;!-- --&gt;在 html 中的意思是的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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