插入HTML属性中的值-Pug(Jade) [英] Interploating values in HTML attributes - Pug(Jade)
本文介绍了插入HTML属性中的值-Pug(Jade)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用Jade中插入的具有href
属性的anchor
标签.
I am trying to construct an anchor
tag with href
attribute interploated in Jade.
我确实通过了 http://jade-lang.com/reference/interpolation/还有一些问题,但并没有帮助我.这就是我尝试过的.
I did go through http://jade-lang.com/reference/interpolation/ and some SO questions but 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屋!
查看全文