在 laravel 中使用刀片变量作为点击函数的参数



我需要 tu 使用一个模板上的变量作为在 html onclik 上调用的 javascript 函数的参数

<p class="brand-product">{{ (brand.brand) }}</p>
<img onclick="myfunction('a', 'b', '<% brand.brand %>', 'b)" 

这种方式会导致错误,如何使用变量作为参数的正确方法?

您也可以在javascript中使用发送到blade的变量,也可以这样做:

<script type='text/javascript'>
var brand = {!! json_encode($brand) !!}
</script>

现在你可以在 js 中添加事件侦听器,如下所示:

$('#your_image').click(myFunction('a', 'b', brand.brand, 'b'))

最新更新