javascript - 如何使用 Laravel Route 添加 Javascript onClick 函数
问题描述
我添加了一个带有 Javascript onClick 函数的链接,如下所示:
我还需要添加一个 Laravel 的路由,所以我添加了这个:
<div onclick="location.href='{{ route(\'shopping-products.show\', $newest->prd_slug) }}';" style="cursor: pointer;">
但这会返回此错误:
syntax error, unexpected ''shopping-products.show\', $ne' (T_CONSTANT_ENCAPSED_STRING), expecting identifier (T_STRING) (View: index.blade.php)
那么如何正确添加带有 Javascript 的 onClick 功能的 Laravel 路由呢?
解决方案
不需要反斜杠
<div onclick="location.href='{{ route('shopping-products.show', $newest->prd_slug) }}';" style="cursor: pointer;">
推荐阅读
- python - 将几个PY文件编译成EXE
- python - BeautifulSoup4 和 w3lib — 为什么我的结果是垂直打印的?如何以 CSV 格式格式化结果?
- python - python中的双变量极坐标图
- javascript - 单击按钮时如何删除d3行
- node.js - 如何使用循环将我的 mongoose/mongodb 数据库中的数据显示到哈巴狗模板中?
- javascript - 使用cheerio 抓取页面效果不佳
- javascript - 如何解决异步搜索选项延迟?
- c++ - 如果在线程睡眠期间更改了原子数据类型,如何在 C++ 中停止线程?
- javascript - 键入时输入文本更改颜色
- xml - XML 图像切换