js passes the data returned by ajax as a parameter to the onclick function

The project used the data returned by ajax as a parameter into the onclick function, as a parameter, the previous return has always been a number, so use the wording:

var name = ret[index].name;

strHtml+= '<tr id=' + ret[index].name + ' οnclick="showDetail(' + name + ')">';

There is no problem, but an error will occur when the returned name contains a combination of numbers and letters, pure letters, and some browser errors are not easy to locate. Here you need to pass in the name as a string, as follows:

strHtml+= '<tr id=' + ret[index].name + ' οnclick="showDetail(\''+name+'\')">';

To solve the problem, pay attention to the nesting of single and double quotation marks and the use of escape characters. You can check the difference between the two in your browser.

Guess you like

Origin blog.csdn.net/qq_43737121/article/details/105982420