html 5上的javascript

html 5上的javascript,javascript,html,jquery,Javascript,Html,Jquery,大家好,请让我知道以下声明的含义 addEvent(window, 'storage', function (event){ if (event.key == 'storage-event-test'){ output.innerHTML = event.newValue; } }); addEvent(dataInput, 'keyup', function (){ localStorage.setItem('storage-event-test',

大家好,请让我知道以下声明的含义

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()方法,以及上面代码的作用。

javascript中没有addEvent方法,可以是外部编写的函数。有

从您的代码中,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);
});
有关本地存储的更多信息,请参阅