繁体   English   中英

HTML 5上的JavaScript

[英]javascript on 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()方法以及以上代码的作用。

javascript没有addEvent方法,可以是外部编写的函数。 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);
});

有关本地存储的更多信息,请参见此处

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM