日期:2014-05-16  浏览次数:20311 次

javascript基础知识大集锦(2)

本期主题:正则表达式 call(),apply(),callee,caller,cookie方法,setInterval(),clearInterval(),setTimeout() ,clearTimeout()


详细看附件例子,还是写的比较简单的。


1.关于cookie的函数:

Js代码 ?收藏代码
  1. /** ?
  2. ?*?cookie操作工具. ?
  3. ?*?使用方法:保存值:CookieTool('name','1',{expires:?7})??//表示保存一个cookie值为1,键值为name,失效时间7天以后 ?
  4. ?*?????????取值:CookieTool('name')????????????????????//返回1 ?
  5. ?*?@param?{}?name ?
  6. ?*?@param?{}?value ?
  7. ?*?@param?{}?options ?
  8. ?*?@return?{} ?
  9. ?*/ ??
  10. CookieTool?=?function (name,?value,?options)?{??
  11. ??????????if ?( typeof ?value?!=? 'undefined' )?{??
  12. ????????????????????options?=?options?||?{};??
  13. ????????????????????if ?(value?===? null )?{??
  14. ??????????????????????????????value?=?'' ;???
  15. ??????????????????????????????options.expires?=?-1;??
  16. ????????????????????}??
  17. ????????????????????var ?expires?=? '' ;??
  18. ????????????????????if ?(options.expires?&&?( typeof ?options.expires?==? 'number' ?||?options.expires.toUTCString))?{??
  19. ??????????????????????????????var ?date;??
  20. ??????????????????????????????if ?( typeof ?options.expires?==? 'number' )?{??
  21. ????????????????????????????????????????date?=?new ?Date();??
  22. ????????????????????????????????????????date.setTime(date.getTime()?+?(options.expires?*?24?*?60?*?60?*?1000));??
  23. ??????????????????????????????}?else ?{??
  24. ????????????????????????????????????????date?=?options.expires;??
  25. ??????????????????????????????}??
  26. ??????????????????????????????expires?=?';?expires=' ?+?date.toUTCString();??
  27. ????????????????????}??
  28. ????????????????????var ?path?=?options.path??? ';?path=' ?+?(options.path)?:? '' ;??
  29. ????????????????????var ?domain?=?options.domain??? ';?domain=' ?+?(options.domain)?:? '' ;??
  30. ????????????????????var ?secure?=?options.secure???