在HTML属性中插值-Pug(Jade) [英] Interpolating values in HTML attributes - Pug (Jade)
本文介绍了在HTML属性中插值-Pug(Jade)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在Jade中使用动态的 href
属性构造一个 anchor
标记.
I am trying to construct an anchor
tag with a dynamic href
attribute in Jade.
我确实查看了文档和一些SO问题,但它们没有帮助我.这就是我尝试过的.
I did go through the docs and some SO questions but they didn't help me. This is what I tried.
a(href= "http://www.imdb.com/title/#{movie.imdb_id}") Know more
但是它呈现
http://www.imdb.com/title/#{movie.imdb_id}
而不是
http://www.imdb.com/title/tt1234567
但这可行
a(href= "http://www.imdb.com/title/" + movie.imdb_id) Know more
也是.
- var url = "http://www.imdb.com/title/" + movie.imdb_id;
a(href= url) Know more
第一个版本出了什么问题?
What's wrong with the first version?
推荐答案
插值仅在文本中可用.
您需要对属性使用JS字符串串联:
You need to use JS string concatenation for attributes:
a(href="http://www.imdb.com/title/" + movie.imdb_id) Know more
如果您的JavaScript运行时支持 ES2015模板字符串,您也可以使用它们(注意反引号):
If you JavaScript runtime supports ES2015 template string, you can also use them (notice the backticks):
a(href=`http://www.imdb.com/title/${movie.imdb_id}`) Know more
这篇关于在HTML属性中插值-Pug(Jade)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文