`
xiaozhi7616
  • 浏览: 191792 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

JavaScript中的一些常用方法

阅读更多
<script type="text/javascript">
	
	/**
	 * Document 对象
	 */
	
	//输出文档标题
    document.write(document.title);
	
	//输出文档的URL
    document.write(document.URL);
	
	//输出文档的加载地址
	document.write(document.referrer);
	
	//输出文档中链接的数目
	document.wirte(document.anchors.length);
	
	//输出文档中第一个链接的文本内容
	document.write(document.anchors[0].innerHTML);
	
	//输出文档中图片的个数
	document.write(document.images.length);
	
	/**
	 * 从上面的例子中可以看出来,JavaScript把anchors和images都作为数组类型的属性封装了起来
	 */
	
	/**
	 * Event 对象
	 */
	
	//判断鼠标点击了左键、右键还是中键
	function whichButton(event) {
		if((event.button & 1) == 1) {
			alert("您点击了鼠标左键");
		}
		if((event.button & 2) == 2) {
			alert("您点击了鼠标右键");
		}
		if((event.button & 4) == 4) {
			alert("您点击了鼠标中键");
		}
	}
	
	//获取鼠标点击的位置坐标
	function show_coords(event) {
		x = event.clientX;
		y = event.clientY;
		alert("X coords: " + x + ", Y coords: " + y);
	}
	
	//获取按键的Unicode码值(这个很常用)
	alert(event.keyCode);
	
	//获取光标在显示屏上的坐标
	function coordinates(event) {
		x = event.screenX;
		y = event.screenY;
		alert("X = " + x + ", Y = " + y);
	} 
	
	//获取光标的绝对坐标
	function coordinates(event) {
		x = event.x;
		y = event.y;
		alert("X = " + x + ", Y = " + y);
	}
	
	/**
	 * Window 对象
	 */
	
	//设置窗口状态栏信息
	window.status = "状态栏信息";
	
	//改变窗口大小
	window.resizeBy(-100, -100);
	
	//滚动文档
	window.scrollBy(100, 100);
	
	//设置定时、停止定时
	function timedCount() {
		setTimeout("timedCount()", 1000);
	}
	
	function stopCount() {
		clearTimeout(t);
	}
	
	/**
	 * Navigator 对象
	 */				
	 
	 //输出浏览器及版本信息
	 var browser = navigator.appName;
	 var b_version = navigator.appVersion;
	 var version = parseFloat(b_version);		
	 document.write("您使用的浏览器: " + browser);
	 document.write("<br />");
	 document.write("版本是: " + version);
</script>

 

一些常用的方法,用到的时候查看。

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics