工作中所写的功能
document.cookie = "key=1";
document.cookie = "name=zhangsan";
cookie中存值形式:key=1,name=zhangsan等
window.onbeforeunload = function () {
// // 刷新、关闭 页面之前,清理cookie中的key值。
// // alert(document.cookie);
// };
//从cookie中获取数据
function getCookie(cookie_name) {
var result = "";
var allcookies = document.cookie;
var cookie_pos = allcookies.indexOf(cookie_name);
if (cookie_pos != -1)
{
cookie_pos += cookie_name.length + 1;
var cookie_end = allcookies.indexOf(";", cookie_pos);
if (cookie_end == -1)
{
cookie_end = allcookies.length;
}
result = unescape(allcookies.substring(cookie_pos, cookie_end));
}
return result;
}
在js中读取//读txt文件 使用到的微软插件时:activeObject;
function readFile(filename) {
var fso = new ActiveXObject("Scripting.FileSystemObject");
var f = fso.OpenTextFile(filename, 1);
var s = "";
while (!f.AtEndOfStream)
s += f.ReadLine() + "\n";
f.Close();
return s;
}
//通过元素的class获取对应的元素
function getElementsByClassName(n) {
var classElements = [], allElements = document.getElementsByTagName('*');
for (var i = 0; i < allElements.length; i++) {
if (allElements[i].className == n) {
classElements[classElements.length] = allElements[i];
}
}
return classElements;
}