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


    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() + " ";            

                      f.Close();           

                    return s;        

              }

    后期不断更新中...

  • 相关阅读:
    循环的其他用法
    if和switch
    Activity and Task Design
    Accessing Resource学习
    Ctrl 和Alt 快捷键设置的原则
    Android代码没有错误,但是运行出错
    Android读取txt文本文档在手机上显示乱码解决方法
    ImageButton介绍及两种透明方案
    Android 的 Button 按钮实现的两种方式
    resdrawable-hdpi ew.png:0: error: invalid symbol: 'new'错误原因是new是关键词呀
  • 原文地址:https://www.cnblogs.com/ysq0908/p/5793038.html
Copyright © 2020-2023  润新知