This是我的代碼:爲什麼我不能從2個函數內部調用該函數?
inserisciMarker();
function scorriAllaLista(param) {
alert(param);
}
function inserisciMarker() {
markerClick = function() {
$('#example').attr("onclick", "scorriAllaLista('hello'); return false;");
};
markerClick();
}
點擊鏈接,Uncaught ReferenceError: scorriAllaLista is not defined
爲什麼?我該如何解決它?
最有可能它沒有全球定義。 'window.scorriAllaLista = scorriAllaLista'爲什麼你用javascript設置onclick屬性而不是綁定一個事件? – 2013-03-20 14:11:58
你不應該使用'attr()'來添加事件處理程序! – epascarello 2013-03-20 14:12:11
@both:我不能,對於這個未解決的問題:http://stackoverflow.com/questions/13033506/why-i-cant-attach-an-dynamic-event-handler-to-this-element – markzzz 2013-03-20 14:13:52