[英]Why I can't call that function from inside 2 functions?
inserisciMarker();
function scorriAllaLista(param) {
alert(param);
}
function inserisciMarker() {
markerClick = function () {
$('#example').attr("onclick", "scorriAllaLista('hello'); return false;");
};
markerClick();
}
clicking on link, Uncaught ReferenceError: scorriAllaLista is not defined
单击链接,
Uncaught ReferenceError: scorriAllaLista is not defined
Why? 为什么? How can I fix it?
我该如何解决?
That's not how you bind event handler using jQuery. 这不是使用jQuery绑定事件处理程序的方式。
Replace 更换
$('#example').attr("onclick", "scorriAllaLista('hello'); return false;");
with 与
$('#example').click(function(){
scorriAllaLista('hello');
return false;
});
If you realy must do it the way you do, you can add the method to the global window
object, similar to this: 如果您确实必须按照自己的方式进行操作,则可以将方法添加到全局
window
对象中,类似于:
window.scorriAllaLista = function(param) {
alert(param);
}
DEMO - add method to window
演示 -向
window
添加方法
As you are already using return false
you might get away with a href="#"
as return false;
由于您已经在使用
return false
您可能会因为href="#"
而不是return false;
already stops propagation as well as prevents default behaviour. 已经停止传播并防止出现默认行为。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.