在" onClick"中通过名为cancelOrderByUrl的函数的第一个参数传递 URL 时我收到这个错误:
SyntaxError: missing ) after argument list
但是,如果要将数字传递给cancelOrderByUrl(**HERE**, not here, not here);
的第一个参数,则没有错误,我的函数会执行。所以它与语法有关,我如何确保将URL封装为字符串?的toString();没有办法。有什么建议吗?
<script src="someScriptThatContainsFunctionBeingCalledInOnClick.js" charset="utf-8"></script>
<script>
var someArray = [{cancel:"hhtps://api.somedomain.com/thisandthat/numbers", quantity:"12", price: "2.74"},{cancel:"hhtps://api.somedomain.com/thisandthat/numbers", quantity:"10", price: "2.71"}];
for (var i = 0; i < someArray.length; i++){
var orderDetails = '<td data-th="Cancel">' + '<button class="btn btn-cancel-order" onclick="cancelOrderByUrl('+someArray[i].cancel+', '+parseFloat(someArray[i].quantity).toFixed(2)+', '+parseFloat(someArray[i].price).toFixed(2)+')" >X</button>' + "</td>";
document.getElementById(someArray[i].created_at).innerHTML = orderDetails;
};
</script>
//if a number is passed instead of url, no problem
&#13;
答案 0 :(得分:0)
您可以尝试使用string.Format()函数。
onclick='@string.Format("cancelOrderByUrl(YOUR PARAMETERS)")'