JS 文本中点击事件传参时报错 Uncaught SyntaxError: missing ) after argument list

157 阅读1分钟

问题描述

遇到的问题:

<button  class="btn-warning" style="border:none;border-radius:2px;" onclick='collection("${curGood}")'>收藏</button>

控制台出现下面问题:

Uncaught SyntaxError: missing ) after argument list

解决方案:

<button  class="btn-warning" style="border:none;border-radius:2px;" onclick='collection(\""+curGood+"\")'>收藏</button>