Why localStorage event monitoring has no effect_html/css_WEB-ITnose

WBOY
Release: 2016-06-24 12:11:13
Original
1093 people have browsed it

I open two pages and after changing the data, why don’t they enter the monitoring and processing events? Please give me some advice. (FireFox 10.0 test)
The code is as follows:

<!DOCTYPE html><html>	<head>		<meta charset = "utf-8" />		<title>LocalStorage </title>		<script type="text/javascript" src="jquery-1.7.1.min.js"></script>		<script type="text/javascript">		   var db = window.localStorage;           if(db)            {              if(window.addEventListener)              {                   window.addEventListener("db",displayStorageEvent);                  console.log('设置监听');              }           }           function displayStorageEvent(e)           {               console.log('进入事件处理');               console.log('改变的字段是'+e.key);               console.log('旧的值是'+e.oldValue);               console.log('新的值是'+e.newValue);                      }           function setdata()           {               if(db)                {                   db.setItem('author', $("#author").val());               }           }                      function showStorage()           {               var s ='';               for(var i=0;i<db.length;i++)               {                   s = s + db.key(i)+ " : " + db.getItem(db.key(i)) + "<br>"                                  }               $("#data")[0].innerHTML = s;           }		</script>	</head>	<body>	    <input type="button" value="显示存储数据" onclick="showStorage()"/>		<form id ="info">		     <label for="author">作者:</label>             <input type="text" name="author" id="author" />             <br/>		     <input type="button" value="设置LocalStorage" onclick="setdata()"/>	    </form>	    <P id="data"></P>	</body>	</html>
Copy after login


Reply to discussion (solution)

This event has never been used

Fainted, did it myself.

window.addEventListener("db",displayStorageEvent); The parameter is not "db"
but
window.addEventListener("storage",displayStorageEvent);
I understood it wrong.



Hey, I am using IE8

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template