JavaScript中的客户端对象

JavaScript中的客户端对象框图如下:


下面详细说明:

1.window对象

window 对象是 JavaScript 层级中的顶层对象。
window 对象代表一个浏览器窗口或一个框架。
window 对象会在 <body> 或 <frameset> 每次出现时被自动创建。



<1>

<html>
<head>
<script>
	function open_win() 
	{   myWindow=window.open();  //打开空白页面
    	    myWindow.document.write("this is myWindow");
    	    myWindow.focus();  
        }
</script>
</head>
<body>
<input type=button value="Open Window" οnclick="open_win()" />
</body>
</html>

<2>

<html>
<head>
<script>
function show_popup()
{	var p=window.createPopup();
	var pbody=p.document.body;
	pbody.style.backgroundColor="lime";
	pbody.style.border="solid black 1px";
	pbody.innerHTML="This is a pop-up! Click outside to close.";
	p.show(150,150,200,50,document.body);   
 }
</script>
</head>
<body>
<button οnclick="show_popup()">Create pop-up!</button>
</body>
</html>

<3>

<html>
<head>
<script>
	function clock()
	{  var t=new Date();
	  document.getElementById("clock").value=t.toLocaleString();  }
</script>
</head>
<body>
	<input type="text" id="clock" size="35" />
	<script>
		var ClockID=window.setInterval("clock()",1000);
	</script>
	<input type="button" value="停止" οnclick="window.clearInterval(ClockID)">
</body>
</html>

<3>运行效果:



2. document对象

每个载入浏览器的 HTML 文档都会成为 document 对象。 
document 对象可用来访问页面中的所有元素。
document 对象是 window 对象的一个部分



示例:

<1>document.getElementById()方法示例

<html>
<head>
<script>
	function getValue()
	{   var x=document.getElementById("username");
	    alert(x.value);    }
</script>
</head>
<body>
	<input type="text" id="username" >
	<input type="button" value="OK" οnclick="getValue()">
</body>
</html>
<2>document.open()示例

<html>
<head>
<script>
	function createNewDoc()
  	{  var newDoc=document.open("text/html","replace");
    	   var txt="<html><body>hello</body></html>";
    	   newDoc.write(txt);
    	   newDoc.close();    }
</script>
</head>
<body>
<input type="button" value="创建一个新文档" οnclick="createNewDoc()">
</body>
</html>

3.location对象

location对象包含有关当前 URL 的信息。 
location 对象是 window 对象的一个部分。


示例:

<html>
<head>
<script>
	function currLocation()
	{  alert(window.location) ;  }
	function newLocation()
	{  window.location="http://www.wust.edu.cn"; }
</script>
</head>
<body>
<input type="button" οnclick="currLocation()" value="显示当前的 URL">
<input type="button" οnclick="newLocation()" value="改变 URL">
</body>
</html>

4. history对象

history 对象包含用户在浏览器窗口中访问过的 URL。
出于隐私方面的原因,history 对象不再允许脚本访问已经访问过的实际 URL。唯一保持使用的功能只有 back()、forward() 和 go() 方法。
history对象是window对象的一部分。



5. navigator对象

navigator对象包含有关浏览器的信息。



6.form对象

form 对象代表一个 HTML 表单。
在 HTML 文档中 <form> 每出现一次,form 对象就会被创建。



示例:

<html><head>
<script>
	function formReset() {  document.myForm.reset()  }
	function formSubmit() {  document.myForm.submit()  }
</script>
</head>
<body> 
<form name="myForm" action="getData.html">
	姓名: <input type="text" size="10" value="wustzz"><br />
	密码: <input type="password" size="10"><br />
	<input type="button" οnclick="formSubmit()" value="提交">
	<input type="button" οnclick="formReset()" value="重置">
</form>
</body></html>


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值