js string concatenation function name parameters quoted problem

Recently trigger when doing the project you want to link an event that requires stitching function name and pass the dynamic parameters, result parameter quotation marks have been caused js error, after a study found the correct wording, as follows:

1. When the function when only one parameter, according to the following wording

 "<a href='javascript:void(0);' title='删除'  onclick=\"deleteCpmx(' "+cjid+" ')\"><span style='color:blue'>删除</span></a>";

 I.e. the parameters used in single quotes reference line

2. When the function when more than two parameters, the following wording

 "<a href='javascript:void(0);' title='删除'  onclick=\"deleteCpmx("+pkey+",' "+cjid+" ')\"><span style='color:blue'>删除</span></a>";

This time before the first parameter double quotation marks are automatically added to the single quotation marks, add quotation marks if it will lead to redundant js error.



The content is simple, the next record indicates that there is progress, come on!


Thanks to the original bloggers

Original link: http: //blog.csdn.net/cjx1991/article/details/77046748

Guess you like

Origin blog.csdn.net/baidu2030/article/details/78531921