js讀取配置文件自寫
更新時間:2014年02月11日 10:01:32 作者:
這篇文章主要介紹了js讀取配置文件的方法,需要的朋友可以參考下
自己寫的用js讀取配置文件的程序
D:\Useful Stuff\Javascript\mytest.txt
文件內(nèi)容如下
復(fù)制代碼 代碼如下:
[plugin_page_search]
wholeword=0
matchcase=1
hightlight=1
total=1
[data]
up=85
down=5
復(fù)制代碼 代碼如下:
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"));
相關(guān)文章
讓插入到 innerHTML 中的 script 跑起來的代碼
讓插入到 innerHTML 中的 script 跑起來的代碼...2007-11-11jquery和css3中的選擇器nth-child使用方法和用途示例
nth-child(),是CSS3中的一個偽類選擇符,JQuery選擇器繼承了CSS的部分語法,允許通過標(biāo)簽名、屬性名、內(nèi)容對DOM元素進(jìn)行快速、準(zhǔn)確的選擇。2023-03-03