我有這個錯誤,它不工作。在jquery點擊事件中傳遞對象
我想調用一個共享函數來警告傳入的數據,這是從兩個不同的點擊事件中調用的,但是|我在警報中得到了定義。爲什麼我得到定義不清?
var myF = function(){
alert('a click ' + this.model + ' ' + this.year); // meant to alert the properties of the object passed to it
alert(this.ID); // meant to alert the ID of the click that called it
};
var myCar = new Object();
myCar.make = "Ford";
myCar.model = "Mustang";
myCar.year = 1969;
var myCar2 = mycar;
myCar2.make = "VW";
myCar2.model = "golf";
myCar2.year = 2000;
$('.feature1').click(myCar,myF);
$('.feature2').click(myCar2,myF);
當你這樣做:MYF(myCar)您呼叫的那一刻該功能。這不會將處理程序添加到點擊功能 – edrian
,這會在點擊 –
之前調用該功能,您需要返回一個功能並且不要直接調用警報 –