我有以下代码:
var len;
var i;
var str;
len=@model.getProduct_to_displaySize();
for(i=0;i<len;i++)
{
document.write("<center>"+
"<a href="JavaScript:Platform.Product.openQuickView(@model.getProductID(i))">"+
"<img src="@model.getProductImgURL(i)">"+
"</a>"+
"</center><br><br>");
}
我正在尝试将参数 i(来自 for 循环)传递到循环内的函数中,但是我收到以下错误:
未找到:值 i
我该如何解决这个问题?谢谢
将i
连接到字符串中:
document.write("<center>"+
"<a href="JavaScript:Platform.Product.openQuickView(@model.getProductID("+i+"))">"+
"<img src="@model.getProductImgURL("+i+")">"+
"</a>"+
"</center><br><br>");
你的语法是错误的,但这个想法是正确的。最好还是尝试这种方式。使用字符串文本。包装我喜欢这个 --> ${i}
例如:<center> <img src="${i.url}"> </center>
使用字符串文本引号可以插入用美元符号和大括号而不是加号括起来的值。