2012-02-17 33 views
0

大家好,请让我知道下面的语句JavaScript的HTML上5

addEvent(window, 'storage', function (event){ 
    if (event.key == 'storage-event-test'){ 
     output.innerHTML = event.newValue; 
    } 
}); 

addEvent(dataInput, 'keyup', function(){ 
    localStorage.setItem('storage-event-test', this.value); 
}); 

请解释一下我的意思是什么的addEvent()方法和做什么呢上面的代码。

回答

2

没有addEvent方法作为javascript的一部分,可能是一个外部编写的函数。有element.addEventListener

你的代码中的addEvent预计此签名:

addEvent(obj, an_event_string, callback_fn); 

第一个参数,我不知道,只是需要一个对象。第二个是表示(我在猜测)事件的字符串,第三个是事件发生时调用的函数。

addEvent(window, 'storage', function (event){ 
    //for the "storage" event this function is called 
    // and some info is passed in the event argument 
    if (event.key == 'storage-event-test'){ //if the key is.. 
     output.innerHTML = event.newValue; 
    }//then set the innerHtml to a value from the event 
}); 

addEvent(dataInput, 'keyup', function(){ 
    //for the "keyup" event 
    //save an item into local storage 
    localStorage.setItem('storage-event-test', this.value); 
}); 

为更多本地存储见here