gpt4 book ai didi

javascript - 语法错误 : missing ) after argument list when onClick calling function and passing url as first argument. JavaScript

转载 作者:行者123 更新时间:2023-11-28 04:43:19 26 4
gpt4 key购买 nike

当通过“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

最佳答案

您可以尝试使用 string.Format() 函数。

onclick='@string.Format("cancelOrderByUrl(YOUR PARAMETERS)")'

关于javascript - 语法错误 : missing ) after argument list when onClick calling function and passing url as first argument. JavaScript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43599311/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com