我試圖通過單擊具有onClick=location.href屬性的按鈕向某個端點發出 GET 請求。但我不知道如何讓 EJS 標簽在撇號內作業。
<button type="button" onclick='location.href="/<%= todoList.title %>"'>delete</button>
我想得到這個結果:
<button type="button" onclick="location.href="/football">delete</button>
而我得到,
<button type="button" onclick="location.href="/">delete</button>
uj5u.com熱心網友回復:
嘗試
<button type="button" onclick='location.href="/<%- todoList.title %>"'>delete</button>
使用<%- %>而不是<%= %>在 JS 中(onclick 函式)
或者
使用鏈接是否使用具有 onclick 功能的按鈕
<a href="/<%= todoList.title %>">delete</a>
// if you use bootstrap as framework
<a href="/<%= todoList.title %>" class="btn">delete</a>
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/356421.html
