日常小记

HTML5设置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 test() { //?取div1
      var div1 = document.getElementById('div1');
      div1.style.backgroundColor="black";
 }

</script>
</head>
<body>
<div id="div1" style="width:400px; height:300px; background-color:red;">div1</div>
<input type="button" value="11" οnclick="test()"/>
</body>
</html>

注意方法名不要和类名一样,实测类名方法名一样的情况下方法不生效且不报错

回复

This is just a placeholder img.