1) When the method has no parameters, the assignment can be directly used by 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() before the method name.
window.onload = function() {$('btnTest').onclick= function() { test(1) }; }function test(val) {alert(val);}