首頁  >  文章  >  web前端  >  js讀取設定檔自寫_javascript技巧

js讀取設定檔自寫_javascript技巧

WBOY
WBOY原創
2016-05-16 17:00:421264瀏覽

自己寫的用js讀取設定檔的程式
D:Useful StuffJavascriptmytest.txt
檔內容物🎜>
程式碼如下:

[plugin_page_search] wholeword=0 matchcase=1 hightlight=1 total=1 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 "));


陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn