HTML IF 语句
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9433448/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
HTML IF Statement
提问by Maggie Fortelli
I just wanna know how to do an if
-statement in simple HTML. Like the [if IE6]
thingy
我只想知道如何if
在简单的 HTML 中做一个-statement。喜欢的[if IE6]
东西
I'd like to do something like this
我想做这样的事情
[IF 5>6]
How's the syntax? I can't seem to find anything but [If!IE6]
and things like that, is that even possible?
语法如何?我似乎什么也找不到,但[If!IE6]
诸如此类,这可能吗?
Thanks a lot
非常感谢
Edit: I want to compare just scalar numbers, cause I have a dynamically created HTML. For example [If 4 == 6]
. I DON'T WANT TO CHECK IE VERSIONS.
编辑:我只想比较标量数字,因为我有一个动态创建的 HTML。例如[If 4 == 6]
。我不想检查 IE 版本。
回答by Anthony Faull
Not in HTML. Consider using JavaScript
instead.
不是在 HTML 中。考虑JavaScript
改用。
回答by devdigital
No, it's not possible. What you have seen is conditional comments in IE, which only checks version numbers of IE, and is typically used to inject IE specific style sheets to fix CSS bugs for that particular browser.
不,这不可能。你看到的是IE 中的条件注释,它只检查 IE 的版本号,通常用于注入 IE 特定的样式表来修复特定浏览器的 CSS 错误。
回答by jrummell
The <!--[if IE]>
syntax only works in Internet Explorer. You'll need to use javascript or css to conditionally display html in other browsers.
该<!--[if IE]>
语法仅适用于 Internet Explorer。您需要使用 javascript 或 css 在其他浏览器中有条件地显示 html。
回答by Nix
If you want to check for browser versions:
如果要检查浏览器版本:
<!--[if lt IE 7]>
<!-- For LOWER than IE7 -->
<![endif]-->
<!--[if IE 6]>
<!-- For JUST IE6 -->
<![endif]-->
<!--[if gt IE 7]>
<!-- For HIGHER than IE7 -->
<![endif]-->
Other than that, you cannot use if statements in HTML, as it is a markup language and not a programming language. You need to do it either server side or with Javascript.
除此之外,您不能在 HTML 中使用 if 语句,因为它是一种标记语言而不是一种编程语言。您需要在服务器端或使用 Javascript 来完成。
回答by punkrockbuddyholly
I believe this is the page you are looking for http://msdn.microsoft.com/en-us/library/ms537512(v=vs.85).aspx
我相信这是您正在寻找的页面http://msdn.microsoft.com/en-us/library/ms537512(v=vs.85).aspx
(I typed into google "IE conditional comments". It was the second result.)
(我输入谷歌“IE 条件评论”。这是第二个结果。)
回答by Jedo
The closest thing I can think of is *NgIf or using ternary expressions in your html using angular - however, the assignment of the variables and the logic of that ngif statement would be done in javascript.
我能想到的最接近的事情是 *NgIf 或使用 angular 在 html 中使用三元表达式 - 但是,变量的分配和该 ngif 语句的逻辑将在 javascript 中完成。
回答by CKKiller
[If lte IE 6]
This selects IE 5, 5.5 and 6. It's the closest to what you want.
这将选择 IE 5、5.5 和 6。它最接近您想要的。