Sono stanco di scrivere jQuery, quindi decido di imparare qualche JavaScript raw. Qualcosa in attachEvent di IE mi ha confuso. Ecco il codice.Cosa c'è 'this' in IE's attachEvent
var btn = document.getElementById('myBtn');
btn.onclick = function(){
alert(window.event.srcElement === this); //true, I know why.
};
btn.attachEvent('onclick', function(event){
alert(event.srcElement === this); //fasle, but why?
});
provo ad usare IE built-in strumenti di debug, ma mi ha appena detto che 'questo' è un oggetto, ma niente di più ... quindi qual è 'questo' in attachEvent di IE?
provare a inviare 'questo' alla console e vedere. usa 'console.log (this)' – Joseph
Ci provo, ma IE mi ha appena detto che è un oggetto, niente di più. – shawjia
hai individuato l'errore "srcElemnt"? Senza la "e" la proprietà dell'evento sarà indefinita (e! == questo). – Bergi