码迷,mamicode.com
首页 > 其他好文 > 详细

在开发项目中有些常用的的实用代码(ps:平时看着无关紧要的,却很容易忘记)

时间:2016-08-21 18:11:41      阅读:144      评论:0      收藏:0      [点我收藏+]

标签:

1,在客户端使用Cookie

  document.cookie = "key=1";

  document.cookie = "name=zhangsan";

  cookie中存值形式:key=1,name=zhangsan等

  // 刷新、关闭 页面之前,清理cookie中的key值。   

  window.onbeforeunload = function () {                           

          // 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;       

    }

 2.在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;        

          }

后期不断更新中...

 

在开发项目中有些常用的的实用代码(ps:平时看着无关紧要的,却很容易忘记)

标签:

原文地址:http://www.cnblogs.com/ysq0908/p/5793038.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!