我想尝试将 record.ItemID 传递给我的 onclick = buy() 函数。但我收到类似“Uncaught SyntaxError: Unexpected end of input”之类的错误
我试过 \"record.ItemID \" 但那当然只是通过了 result.name 的文字字符串
我也试过 (\'' + record.ItemID + '\') 但得到相同的语法错误
function showShop(items) {
let tableContent = "<tr class='orderTitle'><td =imgTable></td><td id = contentTable ></td></tr>\n";
let odd = true;
const addRecord = (record) => {
tableContent += odd ? "<tr class='orderOdd'>" : "<tr class='orderEven'>";
odd = !odd;
tableContent += "<td>" + "<img id = image src="+ "http://redsox.uoa.auckland.ac.nz/ms/MuseumService.svc/shopimg?id=" + record.ItemId + " />" + "</td><td id = content>" + record.Description + "<td><button onclick='buy("+ record.ItemId +")'/> Buy </button></td>";
}
items.forEach(addRecord)
document.getElementById("shop").innerHTML = tableContent;
}
function buy(item){
window.open('http://redsox.uoa.auckland.ac.nz/mss/Service.svc/buy?id='+ item,'_self');
}
慕容3067478
小怪兽爱吃肉
相关分类