I want to pass three parameters to this onclick()
function. but it gives me a syntax error.
element += '<div class="cancel" onclick="remove_game(' + game.id + ',\'' + cellstyle + ',\'' + cellid +'\');">';
It calls the function correctly, but it gives the error below
SyntaxError: missing ) after argument list
remove_game(6,'2, 'game6-cell2);
How can i resolve this issue?
Your '
's and commas are off, so that the second argument appears to be '2, '
, and then there isn't a comma before the third. Assuming you want quotes around the 3rd argument, you'd need something like this:
element += '<div class="cancel" onclick="remove_game(' + game.id + ',' + cellstyle + ',\\'' + cellid +'\\');">';
Tada
var element = document.createElement('div');
element.className = 'cancel';
element.addEventListener('click', function() {
remove_game(game.id, cellstyle, cellid);
}, false);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.