如何使用 Laravel 路由添加 Javascript onClick 函数
How to add Javascript onClick Function with Laravel Route
我添加了一个 link 和 Javascript onClick 函数,如下所示:
我还需要添加一条Laravel的路由,所以我添加了这个:
<div onclick="location.href='{{ route(\'shopping-products.show\', $newest->prd_slug) }}';" style="cursor: pointer;">
但是这个returns这个错误:
syntax error, unexpected ''shopping-products.show\', $ne' (T_CONSTANT_ENCAPSED_STRING), expecting identifier (T_STRING) (View: index.blade.php)
那么如何正确添加Laravel路由Javascript的onClick功能呢?
不需要反斜杠
<div onclick="location.href='{{ route('shopping-products.show', $newest->prd_slug) }}';" style="cursor: pointer;">
我添加了一个 link 和 Javascript onClick 函数,如下所示:
我还需要添加一条Laravel的路由,所以我添加了这个:
<div onclick="location.href='{{ route(\'shopping-products.show\', $newest->prd_slug) }}';" style="cursor: pointer;">
但是这个returns这个错误:
syntax error, unexpected ''shopping-products.show\', $ne' (T_CONSTANT_ENCAPSED_STRING), expecting identifier (T_STRING) (View: index.blade.php)
那么如何正确添加Laravel路由Javascript的onClick功能呢?
不需要反斜杠
<div onclick="location.href='{{ route('shopping-products.show', $newest->prd_slug) }}';" style="cursor: pointer;">