-1
我已經購買了一本關於JavaScript的書籍。我已經瞭解了一切,直到編輯代碼以處理任何事情< IE9JavaScript。瞭解電子/事件
有一個簡單的例子,檢查用戶名輸入超過5個字符。 這很容易。然後他們將事件引入到函數中。
在下面的代碼,我將在我需要幫助的部分意見..
function checkLength(e, minLength) { //I understand parameters, but what is 'e' plugging?
var el, elMsg;
if (!e) { //So... if event doesn't exist.(IE8) then use window.event?
e = window.event;
}
el = e.target || e.srcElement; //What exactly is the event targeting?
elMsg = el.nextSibling;
if (el.value.length < minLength) {
elMsg.innerHTML = 'Username must be ' + minLength + ' characters or more';
} else {
elMsg.innerHTML = '';
}
}
var elUsername = document.getElementById('username');
if (elUsername.addEventListener) {
elUsername.addEventListener('blur', function(e) { //what am i passing?
checkLength(e, 5);
}, false);
} else {
elUsername.attachEvent('onBlur', function(e) {
checkLength(e, 5);
});
}
https://developer.mozilla.org/en-US/docs/Web/API/Event – epascarello
*「我在傳遞什麼?」*字符串「blur」和函數(和「false」) 。 –