HTML 中的大括号
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15279240/
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
Curly brackets in HTML
提问by
I stumbled upon this code:
我偶然发现了这段代码:
<a href="#" class="text1"{text2}>...</a>
What does the {text2}
do? Later on, this HTML is replaced with:
有什么作用{text2}
?后来,这个 HTML 被替换为:
<a href="#" class="text1" {text2} style>...</a>
Is there a way I can retrieve the text2
value with jQuery?
有没有办法text2
用 jQuery检索值?
采纳答案by Greg
In some cases that code is input in, so scripts can actually easily identify a the line. Or in some cases can be an indicator for a database to retrieve and store data once it has been pulled.
在某些情况下,代码是输入的,所以脚本实际上可以很容易地识别一行。或者在某些情况下,可以作为数据库在提取后检索和存储数据的指标。
Or it could be invalid markup, doubtful if the person knows what they are doing.
或者它可能是无效的标记,怀疑这个人是否知道他们在做什么。
But without any other information or variables it is hard to say. But the most common is access for scripts within Php, Javascript, and even C#. Cause they can parse the HTML document and manipulate it. If those braces are used, and it is incorrectly it will cause a parse error.
但是没有任何其他信息或变量就很难说。但最常见的是访问 Php、Javascript 甚至 C# 中的脚本。因为他们可以解析 HTML 文档并对其进行操作。 如果使用了那些大括号,并且使用不正确,则会导致解析错误。
Hopefully that sort of clarifies it.
希望那种澄清它。
Update:
更新:
Yes, jQuery can find it. It is a form of Javascript. You could implement something such as:
是的,jQuery 可以找到它。它是 Javascript 的一种形式。您可以实现以下内容:
$(function() {
var foundString = $('*:contains("{text1}")');
});
There is a vast amount of data that addresses this for more detail.
有大量数据可以解决此问题以获取更多详细信息。
回答by Glitches
It does nothing in HTML. It's actually invalid markup. Looks like maybe you have a template system that finds and replaces that before it gets rendered to the browser.
它在 HTML 中什么都不做。它实际上是无效的标记。看起来您可能有一个模板系统,可以在它呈现给浏览器之前找到并替换它。
回答by SilentVoid
I know that in jinja2, a python templating system, brackets contain commands to the template engine, either as:
我知道在 jinja2 中,一个 python 模板系统,括号包含模板引擎的命令,或者是:
Hello, {{varName}}
or:
或者:
<ol>
{%for l in varList%}
<li>{{l}}</li>
{%endfor%}
</ol>
That's in jinja, but jinja has similar syntax to django templates, and many other template engines probably copy django's syntax also.
那是在 jinja 中,但 jinja 的语法与 django 模板相似,许多其他模板引擎也可能复制 django 的语法。
回答by Vincent Tang
its used in angular jsand are called expressions {{expression}}
它在angular js 中使用,被称为表达式{{expression}}
AngularJS is a JavaScript framework. It can be added to an HTML page with a tag.
AngularJS extends HTML attributes with Directives,and binds data to HTML with Expressions.
AngularJS 是一个 JavaScript 框架。它可以添加到带有标签的 HTML 页面中。
AngularJS 使用Directives扩展 HTML 属性,并使用Expressions将数据绑定到 HTML 。