初学JavaScript笔记(三)

本文介绍了JavaScript中对象的创建及属性访问方法,并演示了如何使用eval动态生成代码。此外,还展示了如何在HTML FrameSet中操作不同帧,实现刷新等交互功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

JavaScript对象

<script language="javascript">
	//js中定义了一个构造器
	function Person(){
	}
	var person1=new Person();
	person1.age=18;
	person1.name="wangyec";
	alert(person1.age+"-----"+person1.name);
	//还可以通过以下方式来访问对象的属性
	alert(person1["name"]+"------->"+person1["age"]);
	//还可以动态的生成JavaScript代码
	eval("alert(person1.name);");
	//动态生成js的好我们可以控制代码生成
	var x="name";
	eval("alert(person1."+x+");");
	//另外在动态生成代码时,我试了以下似乎只可以以点的方式来访问属性。
</script>

 

html frameSet

<html>
	<head>
	</head>
	<frameset rows="50%,50%">
	<frame name="top" src="IP的验证.html">
	<frame name="bottom" src="javascript_1.html">
	</frameset>
	<>
</html>

 

操作frame

//在top 页面中刷新bottom页面的方法1
		<input type="button" value="刷新" onclick="window.parent.frames[1].location.reload()"/>
		//在top 页面中刷新bottom页面的方法2
		<input type="button" value="刷新" onclick="parent.frames.bottom.location.reload()"/>
		//在top 页面中刷新bottom页面的方法3
		<input type="button" value="刷新" onclick="parent.frames['bottom'].location.reload()"/>
		//在top 页面中刷新bottom页面的方法4
		<input type="button" value="刷新" onclick="parent.frames.item(1).location.reload()"/>
		//在top 页面中刷新bottom页面的方法5
		<input type="button" value="刷新" onclick="parent.frames.item('bottom').location.reload()"/>
		//在top 页面中刷新bottom页面的方法6
		<input type="button" value="刷新" onclick="parent.bottom.location.reload()"/>
		//在top 页面中刷新bottom页面的方法7
		<input type="button" value="刷新" onclick="parent['bottom'].location.reload()"/>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值