仰天大笑出门去,我辈岂是蓬蒿人。
相信做网站对JavaScript再熟悉不过了,它是一门脚本语言,不同于Python的是,它是一门浏览器脚本语言,而Python则是服务器脚本语言,我们不光要会Python,还要会JavaScript,因为它对做网页方面是有很大作用的。
history.go(0)
location.reload()
location=location
location.assign(location)
document.execCommand('Refresh')
window.navigate(location)
location.replace(location)
document.URL=location.href
function addEventhandler(target,type,fn,cap){
if(target.addEventListener) /*添加监听事件*/
{
target.addEventListener(type,fn,cap)
}
else{
target.attachEvent('on'+type,fn) /*IE添加监听事件*/
}
}
function removeEventhandler(target,type,fn,cap){
if(target.removeEventListener) /*删除监听事件*/
{
target.removeEventListener(type,fn,cap)
}
else{
target.detachEvent('on'+type,fn) /*IE删除监听事件*/
}
}
function bu(event)
{
var bt= window.button || event.button;
if (bt==2)
{
x=event.clientX
y=event.clientY
alert("您点击了鼠标右键!坐标为:"+x+','+y)
}
else if(bt==0)
{
a=event.screenX
b=event.screenY
alert("您点击了鼠标左键!坐标为:"+a+','+b)
}
else if(bt==1)
{
alert("您点击了鼠标中键!");
}
}
function k(event)
{
var ke=event.keyCode || event.which
if(event.shiftKey==1)
{
alert('您点击了shift');
}
alert(ke)
alert(event.type)
}
var w=document.body.offsetWidth|| document.documentElement.clientWidth|| document.body.clientWidth;
var h=document.body.offsetHeight|| document.documentElement.clientHeight || document.body.clientHeight;
window.innerHeight - 浏览器窗口的内高度(以像素计)
window.innerWidth - 浏览器窗口的内宽度(以像素计)
var t=document.documentElement.scrollTop || document.body.scrollTop
var s=document.documentElement.scrollLeft || document.body.scrollLeft
function off(o){ #元素内容距离浏览器边框的距离(含边框)
var l=0,r=0;
while(o){
l+=o.offsetLeft+o.clientLeft;
r+=o.offsetTop+o.clientTop;
o=o.offsetParent;
}
return {left:l,top:r};
}
// 滚动条的高度
function getScrollTop() {
var scrollTop = 0;
if (document.documentElement && document.documentElement.scrollTop) {
scrollTop = document.documentElement.scrollTop;
}
else if (document.body) {
scrollTop = document.body.scrollTop;
}
return scrollTop;
}
function next(o){//获取下一个兄弟节点
if (o.nextElementSibling) {
return o.nextElementSibling;
} else{
return o.nextSibling;
};
}
function pre(o){//获取上一个兄弟节点
if (o.previousElementSibling) {
return o.previousElementSibling;
} else{
return o.previousSibling;
};
}
function first(o){//获取第一个子节点
if (o.firstElementChild) {
return o.firstElementChild;//非IE678支持
} else{
return o.firstChild;//IE678支持
};
}
function last(o){//获取最后一个子节点
if (o.lastElementChild) {
return o.lastElementChild;//非IE678支持
} else{
return o.lastChild;//IE678支持
};
}
document.body.scrollWidth||document.docuemntElement.scrollWidth;//整个网页的宽
document.body.scrollHeight||document.docuemntElement.scrollHeight;//整个网页的高
window.screen.height;//屏幕分辨率的高
window.screen.width;//屏幕分辨率的宽
window.screenLeft;//x坐标
window.screenX;//X坐标
window.screenTop;//y坐标
window.screenY;//y坐标
window.screen.availHeight
window.screen.availWidth
e.target || e.srcElement
funtion getStyle(obj,name){
if(obj.currentStyle){
//IE
return obj.currentStyle[name];
}else{
//Chrom,FF
return getComputedStyle(obj,false)[name];
}
}
function pre(event){
var e = event || window.event;
if(e.stopPropagation){ // 通用方式阻止冒泡行为
e.stopPropagation();
}else{ //IE浏览器
event.cancelBubble = true;
}
function stop(event) {
var e = event || window.event;
if (e.preventDefault){
e.preventDefault(); // 标准浏览器
}else{
e.returnValue = false; // IE浏览器
}
}
"use strict"
typeof variable
instance instanceof object
instance.constructor== object
Object.prototype.toString.call(instance)
<a href="http://somehost/somefile.zip" download="myfile.zip">Download file</a>
这篇文章主要介绍了JavaScript的进阶操作命令!希望对大家的学习有所帮助。
看完本文有收获?请转发分享给更多的人
IT共享之家
联系客服