JS知识点小集合
1、浏览器宽度与高度:
可见区域宽度:document.documentElement.clientWidth可见区域高度:document.documentElement.clientHeight
网页可见区域宽: document.body.clientWidth 网页可见区域高: document.body.clientHeight 网页可见区域宽: document.body.offsetWidth (包括边线的宽) 网页可见区域高: document.body.offsetHeight (包括边线的高) 网页正文全文宽: document.body.scrollWidth 网页正文全文高: document.body.scrollHeight

2、获取URL中指定参数的值:
name:URL中参数名称
如果想一次获取所有参数的值,可以对该函数进行一下改造即可。
function GetQueryString(name) { var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); var r = window.location.search.substr(1).match(reg); if (r != null)return decodeURI(r[2]); return null;}

3、滚动条有效但不显示:
在CSS中加入以下语句后,可以在页面上呈现出滚动条的效果(可以上下滚动)但在页面上看不到滚动条。新测Google浏览器是有效的,其它浏览器可以自己尝试一下。
::-webkit-scrollbar { width: 0;}

4、读写Cookie的方法:
通过以下函数可以实现JS对Cookie的操作。简单方便。
function setCookie(name,value){ var Days = 30; var exp = new Date(); exp.setTime(exp.getTime() + Days*24*60*60*1000); document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();}function getCookie(name){ var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)"); if(arr=document.cookie.match(reg)) return unescape(arr[2]); else return null;}function delCookie(name){ var exp = new Date(); exp.setTime(exp.getTime() - 1); var cval=getCookie(name); if(cval!=null) document.cookie= name + "="+cval+";expires="+exp.toGMTString();}

5、调用Python代码:
var data = {"kind": "user_login", "table": table, "query_condition_field_list": JSON.stringify([field]), "query_condition_value_list": JSON.stringify([value])}; // 要传递给python的数据// 这里不用 $.post的原因在于$.post不指定同步请求$.ajax({ type : "post", url : "/mp/index.py", // 调用的Python文件
data : data, async : false, // 指定同步请求 dataType:'json', success : function(recv_data) { if(recv_data["return_data"]["email"] == "") { // 已存在该用户 result = true; } }});

6、获取当前日期:获取日期是一个很常用的操作,通过以下函数就可以得到当前的日期。如果需要其它日期,也可以通过该函数进行调整。
function getNowFormatDate(style) { var currentdate = ""; var date = new Date(); var seperator1 = "-"; var month = date.getMonth() + 1; var strDate = date.getDate(); if (month >= 1 && month <= 9) { month = "0" + month; } if (strDate >= 0 && strDate <= 9) { strDate = "0" + strDate; } if(style == "YMD") { // 年月日 currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate; return currentdate; } else { // 年月日 时分秒 var seperator2 = ":"; currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate + " " + date.getHours() + seperator2 + date.getMinutes() + seperator2 + date.getSeconds(); return currentdate; }}

7、进行页面跳转:
以下的方式都可以打开一个新的页面。但具体的功能稍有不同。可以根据自己的需求进行选择。
window.location.href = "url" // 跳转到指定的URL
window.history.back(-1); // 返回
window.open("url"); // 跳转到指定的URL
<a href="url" title="打开URL" target="_blank">Welcome</a> // 打开一个新的窗口。
