js读取配置文件自写_javascript技巧
程序员文章站
2022-05-18 09:49:51
...
自己写的用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"));
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"));
推荐阅读
-
javascript - 用js自写ajax提交表单数据到php,但是php的$_POST为空?
-
js写的评论分页(还不错)_javascript技巧
-
js写的评论分页(还不错)_javascript技巧
-
js解析json读取List中的实体对象示例_javascript技巧
-
纯js写的分页表格数据为json串_javascript技巧
-
自己使用js/jquery写的一个定制对话框控件_javascript技巧
-
如何写JS数组sort的比较函数_javascript技巧
-
js解析json读取List中的实体对象示例_javascript技巧
-
可以读取EXCEL文件的js代码_javascript技巧
-
根据配置文件加载js依赖模块_javascript技巧