0
如何將JS數組轉換爲外部腳本? 我有智者陣列{} myArray的這個代碼:如何將JS數組轉換爲外部腳本
<li onclick='myfunction("{myarray}")'>TRANSFER</li>
externalscript.js樣子:
function myfunction(myarray)
{
var content = '<table class="table-data-sheet" id="table">';
{foreach $myarray key=k item=f}
content +='<tr>';
content += '<td>' + "{$k}" + '</td>' + '<td>' + "{$f}" + '</td>';
content += '</tr>';
{/foreach}
content += '</table>';
document.getElementById("table").innerHTML = content;
}
但它不工作。我不知道爲什麼。 我可以傳遞變量但不是數組。
好像你發送一個普通字符串「{myArray的}」,你試過沒有雙引號,只是發送{} myArray的? – randomguy04