调用变量值以获取IMG源值
因此,我是新来的哈巴狗和编程。我想获得IMG源并根据变量名称进行打印。我想做的是:
- var values = ['car', 'space', 'plants', 'rock', 'chair', 'phone', 'television'];
然后,我会做一个迭代此数组的迭代,并根据单词进行随机打印,例如:
each val in values.length ? values : ['There are no values']
img(src="https://source.unsplash.com/featured/1200x900?"+val alt=val loading="lazy")
我尝试了不同的方法,但似乎不知道如何使用和打印图片帕格。我试图使用它来调用它:
img(src="https://source.unsplash.com/featured/1200x900?values[0]", alt="random")
但是只有我只是说:
img(src="https://source.unsplash.com/featured/1200x900?car", alt="random")
So I'm new with PUG and programming. I want to get img source and print it depending on the variable name. What I want to do is:
- var values = ['car', 'space', 'plants', 'rock', 'chair', 'phone', 'television'];
Then I'll do a for to iterate over this array and print random unplash depending on the word, something like:
each val in values.length ? values : ['There are no values']
img(src="https://source.unsplash.com/featured/1200x900?"+val alt=val loading="lazy")
I have tried different ways but can't seem to know how to call and print pictures using PUG. I tried to call it using:
img(src="https://source.unsplash.com/featured/1200x900?values[0]", alt="random")
But only works if I just say:
img(src="https://source.unsplash.com/featured/1200x900?car", alt="random")
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的哈哈代码:
生成HTML:
您期望什么?怎么了?
您可以在任何在线转换器中进行自我测试,例如: https://www.ubercompute .com/pug-to-html
Your Pug code:
generate HTML:
What do you expect? What is wrong?
You can self test your Pug code in any online converter, e.g. here: https://www.ubercompute.com/pug-to-html