简体   繁体   中英

How to pass parameters in dynamic link for onClick function

Hey I am creating dynamic link as below. Here I am calling a function to go to the required page. I want to pass the parameters with function.

 $.each(data, function(key, value) {
        var str = value.split(':');
        trHTML += '<tr><td><a href="#" onClick="forward('+key+','+value+');">'+str[0]+'</a></td><td class="col-xs-4">'+str[1]+'</td><td class="col-xs-4">'+key+'</td></tr>';
        });

This is creating a link like this :

<a onclick="forward(241,vaibhavs:3847);" href="#">vaibhavs</a>

I know there is some problem with these parameters. They are going as variable names rather than values. The error as shown by Firebug is :

**SyntaxError: missing ) after argument list

     forward(241,vaibhavs:3847);**

So please guys suggest me the correct way to pass the parameters here.

尝试提供报价,

<a onclick="forward('241','vaibhavs:3847');" href="#">vaibhavs</a>

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM