Home > Article > Web Front-end > js dynamically adds onclick event that can pass parameters or not_javascript skills
1) When the method has no parameters, the value can be assigned directly using onclick = method name
window.onload = function() { $('btnTest').onclick = test; } function test() { alert(val); }
2) When the method has parameters, it is wrong to use onclick = method name (parameter). You need to add function()
in front of the method name.window.onload = function() { $('btnTest').onclick= function() { test(1) }; } function test(val) { alert(val); }