Passing object parameters in javacript onclick event

How to pass object parameters in the onclick event of javascript, documented as follows:

var user = {id:1, name:'zhangsan', age:25};

var ele = '<a onclick="edit(' + JSON.stringify(user).replace(/"/g, '&quot;') + ');">修改</a>';

或者

var ele = '<a onclick="edit(\'' + JSON.stringify(user).replace(/"/g, '&quot;') + '\');">修改</a>';

The former gets a json object, and the latter gets a json string.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325892447&siteId=291194637