超链接显示时间
主要使用的语法:retrun false
什么也不执行,取消默认事件
(event.returnValue=false) 这种方式不推荐使用,考虑到兼容性问题.
当前时间:
new Date().toLocaleTimeString()
locale:场所,现场
实例:
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="Generator" content="EditPlus®">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<title>Document</title>
<script type='text/javascript'>
onload=function(){
document.getElementById('ak').onclick=function(){
if(event.shiftKey){
alert(new Date().toLocaleTimeString()); //注意这里有个e
//注意,如果不加下面这一句代码,则页面弹出时间后也会跳转过去
return false;//什么也不执行,取消默认事件
//event.returnValue=false;//ie可以,火狐不行 event需要考虑兼容性
}
};
};
</script>
</head>
<body>
<a href='http://www.baidu.com' id='ak'>百度</a>
</body>
</html>
获取界面分辨率
关键词:screen
语法:screen.width 界面宽度.screen.height 界面高度
实例:
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="Generator" content="EditPlus®">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<title>Document</title>
<script type='text/javascript'>
onload=function(){
document.getElementById('btn').onclick=function(){
alert(screen.width+','+screen.height);
};
};
</script>
</head>
<body>
<input type='button' value='显示分辨率' id='btn'/>
</body>
</html>
判断鼠标按键
关键词:button
语法:event.button
注意:因为event,兼容性需要考虑
实例:
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="Generator" content="EditPlus®">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<title>Document</title>
<script type='text/javascript'>
onload=function(){
document.getElementById('dv').onclick=function(){
alert(event.button);
};
};
</script>
</head>
<body>
<div id='dv' style='width:200px;height:200px;background-color:green;'>
</div>
</body>
</html>