You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
functiongetPageHeight(){varg=document,a=g.body,f=g.documentElement,d=g.compatMode=="BackCompat"
? a
: g.documentElement;returnMath.max(f.scrollHeight,a.scrollHeight,d.clientHeight);}
functiongetPageWidth(){varg=document,a=g.body,f=g.documentElement,d=g.compatMode=="BackCompat"
? a
: g.documentElement;returnMath.max(f.scrollWidth,a.scrollWidth,d.clientWidth);}
varGLOBLE_PARAMS=(function(){varargs=newObject();varquery=location.search.substring(1);varpairs=query.split("&");// Break at ampersandfor(vari=0;i<pairs.length;i++){varpos=pairs[i].indexOf('=');if(pos==-1)continue;varargname=pairs[i].substring(0,pos);varvalue=pairs[i].substring(pos+1);value=decodeURIComponent(value);args[argname]=value;}returnargs;})();
/** * Camelize a string, cutting the string by multiple separators like * hyphens, underscores and spaces. * * @param {text} string Text to camelize * @return string Camelized text */functioncamelize(text){returntext.replace(/^([A-Z])|[\s-_]+(\w)/g,function(match,p1,p2,offset){if(p2)returnp2.toUpperCase();returnp1.toLowerCase();});}// someDatabaseFieldNameconsole.log(camelize("some_database_field_name"));// someLabelThatNeedsToBeCamelizedconsole.log(camelize("Some label that needs to be camelized"));// someJavascriptPropertyconsole.log(camelize("some-javascript-property"));// someMixedStringWithSpacesUnderscoresAndHyphensconsole.log(camelize("some-mixed_string with spaces_underscores-and-hyphens"));
字符串反驼峰化
/** * Decamelizes a string with/without a custom separator (underscore by default). * * @param str String in camelcase * @param separator Separator for the new decamelized string. */functiondecamelize(str,separator){separator=typeofseparator==='undefined' ? '_' : separator;returnstr.replace(/([a-z\d])([A-Z])/g,'$1'+separator+'$2').replace(/([A-Z]+)([A-Z][a-z\d]+)/g,'$1'+separator+'$2').toLowerCase();}// some database field name (separate with an empty space)console.log(decamelize("someDatabaseFieldName"," "));// some-label-that-needs-to-be-camelized (separate with an hyphen)console.log(decamelize("someLabelThatNeedsToBeCamelized","-"));// some_javascript_property (separate with underscore)console.log(decamelize("someJavascriptProperty","_"));
The text was updated successfully, but these errors were encountered:
说明
我们都知道函数在JavaScript中的地位是非常重要的,函数式编程是这门语言的精髓,本文不会在这里针对函数去展开,后面我会详细介绍JavaScript的函数式编程的一些概念,这里主要是收集一些我们平时常用到的函数,如果能熟练应用的话会对你的编程速度有很大的提高。希望能帮助到更多的人。
常用函数集合
1.将类数组对象转换为真数组
2.判断是否移动设备访问
3.获取当前路径
4.字符串长度截取
5.替换全部
6.清除空格
7.判断是否以某个字符串开头,结束
8.转义html标签
9.判断是否为数字类型
10.设置cookie值
11.获取cookie值
12.加载样式文件
13.返回脚本
14.清除脚本
15.动态加载脚本
16.返回按ID检索的元素对象
17.跨浏览器绑定事件
18.跨浏览器删除事件
19.为元素添加on方法
20.为元素添加trigger方法
21.getElementsByClassName
22.获取页面高度
23.获取页面scrollLeft
24.获取页面可视宽度
25.获取页面宽度
26.获取页面scrollTop
27.获取页面可视高度
28.获取窗体可见范围的宽与高
29.去掉url前缀
30.断鼠标是否移出事件
31.获得URL中GET参数值
32.清除相同的数组
33.按字母排序,对每行进行数组排序
34.字符串反序
35.清除html代码中的脚本
36.实现base64解码
37.实现utf8解码
38.随机数时间戳
39.获取网页被卷去的位置
40.检验URL链接是否有效
41.获取URL中的参数
The text was updated successfully, but these errors were encountered: