如何在(Jade)pug中将值传递给onclick函数? [英] How to pass value to a onclick function in (Jade)pug?

查看:112
本文介绍了如何在(Jade)pug中将值传递给onclick函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是玉的新手,所以一直坚持这个问题.我想我已经尝试了StackOverflow帖子中的所有内容,但仍然一无所获.

I am new to jade and stuck on this issue. I think I have tried everything from the StackOverflow posts and still at nothing.

我尝试过的事情

button(type='button' class=' c-btn-blue c-btn-circle c-btn-uppercase' value="Read More" onclick='gotoBlog( #{val.link} )')

错误

1:8 Uncaught SyntaxError: Invalid or unexpected token

将其更改为!{val.link}

错误

Uncaught SyntaxError: Unexpected token .

将其更改为!{val.link}" #{val.link}" 仅能使我理解字符串.BTW val.link是一个字符串

Changing it to "!{val.link}" and "#{val.link}" just gives me string understandably so. BTW val.link is a string

只需给出val.link即可说未捕获的ReferenceError:未定义val

Just giving val.link says Uncaught ReferenceError: val is not defined

我现在没有选择了.帮助将不胜感激.

I am out of options now. Help will be appreciated.

谢谢

推荐答案

向html元素添加属性时,您已经在pug的范围之内,因此您可以只使用pug变量,例如常规js变量.

When adding attributes to an html element, you are already within the scope of pug, so you can just use pug variables like regular js variables.

button(type='button' class=' c-btn-blue c-btn-circle c-btn-uppercase' value="Read More" onclick='gotoBlog(' + val.link + ')')

这篇关于如何在(Jade)pug中将值传递给onclick函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆