码迷,mamicode.com
首页 > Web开发 > 详细

Js 通过点击改变css样式

时间:2015-03-09 18:53:16      阅读:6247      评论:0      收藏:0      [点我收藏+]

标签:

通过js 点击按钮去改变目标原始的背景颜色

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>Change.html</title>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    
    <!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
  <script language="javascript">
     function test4(event) {
	   if(event.value == "11") {
	      //?取div1
	      var div1 = document.getElementById(‘div1‘);
	      div1.style.backgroundColor="black";
	   }
	   if(event.value == "22") {
	      //?取div1
	      var div1 = document.getElementById(‘div1‘);
	      div1.style.backgroundColor="red";
	   }
	 }
  </script>
</head>
<body>
  <div id="div1" style="width:400px; height:300px; background-color:red;">div1</div>
  <input type="button" value="11" onclick="test4(this)"/>
  <input type="button" value="22" onclick="test4(this)"/>

  </body>
</html>

 

Js 通过点击改变css样式

标签:

原文地址:http://www.cnblogs.com/sunxun/p/4324174.html

(10)
(1)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!