怎么把QQ浏览器上的视频保存 在浏览器上保存数据

在浏览器上保存数据
JavaScript 能做的事 并不局限于访问HTML 表单的数据 它还能让你创建自己的对象——也就是让你创建储存于客户端的数据 你甚至还能建立包含其它对象的对象 为什么需要这些功能?一个好的理由就是创建数组(array) 简单来说 数组是一个含有几组相关信息的表格或数据库 在下面的例子当中 我们定义了一个叫做taxTable的对象 该对象包含一个数组 而该数组由五个 name 对象实例所组成 这个数组保存五个州的州名 以及它们相关的税率 然后 当用户在订购表单中输入州名时 我们就在数组中检查它 并自动应用正确的税率 创建一个 x 的数组 与使用一个快速的 if then 序列来测试州名相比 使用数组似乎还要做额外的工作 不过 随着条目个数的增加 数组的功能也就变得愈来愈强大 不妨想象有一个拥有五十个州 或五百个销售区 亦或是五千个城市的表格 有了一个数组 你就能够一次建立条目列表 然后每当用户输入新数据时 就可迅速加以引用这个条目列表 下面这个特殊的JavaScript 代码 开始就像我们的计算(calculation)示例一样 不过这一次 我们并不止于简单的数学计算 function state(stateName stateTax){ //fill the instance with the values passed in this name=stateName; this tax=stateTax; //then return the instance of state return this;}
上面定义的state() 函数创建了包括州名与税率的一个州(state)的实例 然而 我们的州此时似乎什么值都没有 下面我们给它们一些值吧
function taxTable(){ //the instance of taxTable is filled with //an array of state objects this[ ]=new state( AZ ); this[ ]=new state( HI ); this[ ]=new state( TX ); this[ ]=new state( NJ ); this[ ]=new state( ); //return the newly created taxTable to //the calling function return this;}
现在 无论taxTable函数何时被调用 我们都创建了五个不同的州实例 分别编号为 到 这样一来 我们就创建了一个数组 来保存我们所有的税率信息 现在我们需要加以处理一番 functioncalculateTax(stateValue){ var index= ; var result= ; var temp= ; 首先 我们定义一个称为calculateTax的函数 calculateTax会以初始化一些变量开始 然后 它需要从用户那里取得一个值 //while there s an instance of state //in the taxGuide array while (taxGuide[index]) { //if the state passed in is in the //taxGuide array if (stateValue toUpperCase() == taxGuide[index] name) { // put the correct tax rate in result result = taxGuide[index] tax; } index++; }
lishixinzhi/Article/program/Java/JSP/201311/19178