为什么我不能从2个函数内部调用该函数?

mar*_*zzz 0 javascript jquery function

是我的代码:

inserisciMarker();

function scorriAllaLista(param) {
    alert(param);
}

function inserisciMarker() {
    markerClick = function () {
        $('#example').attr("onclick", "scorriAllaLista('hello'); return false;");
    };

    markerClick();
}
Run Code Online (Sandbox Code Playgroud)

点击链接, Uncaught ReferenceError: scorriAllaLista is not defined

为什么?我该如何解决?

Den*_*ret 10

这不是你如何使用jQuery绑定事件处理程序.

更换

$('#example').attr("onclick", "scorriAllaLista('hello'); return false;");
Run Code Online (Sandbox Code Playgroud)

$('#example').click(function(){
    scorriAllaLista('hello');
    return false;
});
Run Code Online (Sandbox Code Playgroud)