js读取配置文件自写_javascript技巧

js教程评论486 views阅读模式

自己写的用js读取配置文件的程序

D:\Useful Stuff\Javascript\mytest.txt

文件内容如下

复制代码 代码如下:

[plugin_page_search]

wholeword=0

matchcase=1

hightlight=1

total=1

[data]

up=85

down=5

复制代码 代码如下:

var fso = new ActiveXObject("Scripting.FileSystemObject");

var f = fso.OpenTextFile("D:\\Useful Stuff\\Javascript\\mytest.txt",1);

var s = "";

while (!f.AtEndOfStream)

{

s+= f.ReadLine();

}

f.Close();

function getINI(item,key)

{

new RegExp("\\["+item+"\\](.+)").exec(s);

var str=RegExp.$1;

var reg2=/(\w+)=(\d+)/;

var keyValue={};

str.replace(reg2,function(a,b,c){

keyValue[b]=c;

});

return keyValue[key];

}

alert(getINI("data","up"));

alert(getINI("plugin_page_search","hightlight"));

企鹅博客
  • 本文由 发表于 2019年9月30日 17:10:51
  • 转载请务必保留本文链接:https://www.qieseo.com/419361.html

发表评论