sunxun

Js 通过点击改变css样式

通过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>

 

分类:

技术点:

相关文章:

  • 2022-02-01
  • 2021-12-04
  • 2021-11-18
  • 2021-12-23
  • 2021-11-29
  • 2021-12-03
  • 2021-12-23
  • 2021-12-23
猜你喜欢
  • 2022-01-05
  • 2022-02-02
  • 2022-12-23
  • 2022-12-23
  • 2021-12-22
  • 2022-01-22
  • 2021-12-31
相关资源
相似解决方案