最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - pass multiple parameter in an onclick function - Stack Overflow

programmeradmin6浏览0评论

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?

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?

Share Improve this question edited Apr 6, 2015 at 21:25 Kalle Richter 8,78729 gold badges93 silver badges207 bronze badges asked Apr 6, 2015 at 19:45 NeeroNeero 2262 gold badges7 silver badges23 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 4

Your ''s and mas are off, so that the second argument appears to be '2, ', and then there isn't a ma 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);
发布评论

评论列表(0)

  1. 暂无评论