首页 > 编程语言 > 详细

JavaScript-14(操纵属性和window)

时间:2018-04-16 20:13:52      阅读:166      评论:0      收藏:0      [点我收藏+]
<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>用JS操纵属性和window</title>
		<style type="text/css">
			.tiaozhuan{
				width: 50px;
				height: 20px;
				border-radius: 5px;
				background-color: orange;
				color: white;
				text-align: center;
				line-height: 20px;
				margin-top: 12px;
			}
		</style>
	</head>
	<body>
		<!--创造一个图片,然后用js实现点击它更换引用路径-->
		<img src="../img/fengjing.jpg" width="300px"height="170px" onclick="ghlj()"/>
		<!--点击下面的跳转,通过函数运用window.location.href命令将窗口跳转到指定路径-->
		<div class="tiaozhuan" onclick="tiaozhuan1()">
			跳转
		</div>
		<!--点击下面的刷新,通过函数运用window.location.reload()命令将窗口刷新-->
		<div class="tiaozhuan" onclick="shuaxin()">
			刷新
		</div>
		<!--点击下面的向后翻页,通过函数运用window.history.go(1)命令将窗口向后翻,如果将()中改为-1,则向前翻页-->
		<div class="tiaozhuan" onclick="xh()">
			向后翻页
		</div>
		
	</body>
</html>

<script type="text/javascript">
	//用tupian这个变量接收img标签的集合
	var tupian = document.getElementsByTagName("img");
	//运用getAttribute获得这个图片的src属性值;运用setattribute命令把这个图片的“src”属性设为想要改变的图片路径
	function ghlj(){
		alert(tupian[0].getAttribute("src"));
		tupian[0].setAttribute("src","../img/aiji.jpg");
	}
	function tiaozhuan1(){
		window.location.href = "../0328/HTMLjiaocheng.html";
	}
	function shuaxin(){
		window.location.reload();
	}
	function xh(){
		window.history.go(1);
	}
</script>

  

JavaScript-14(操纵属性和window)

原文:https://www.cnblogs.com/zhangrui0328/p/8858112.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!