[Programming problem] Write a function to click the change button to add a red double border to the div element.

Write a function to click the change button to add a red double border to the div element.

First write a < div > in < body >

<body>
	<div id="k">输入文字</div>
	<input type="button" value="change"/>
</body>

The output is
Insert picture description here
After you have these, you can set the css style of < div > in < head >

<head>
		<meta charset="utf-8">
		<title>Change</title>
		<style type="text/css">
			div {
				width:auto;
				height:auto;
				margin-bottom: 20px;
				margin-left: 20px;
			     }
		</style>
</head>		

Once you have the CSS style, you can use the buttons above to control the style of < div >. The
most important thing is < script >
yon

<script>
	function change() {
	document.getElementById("k").style.border="5px double red"	
			          }		
</script>

The " k " here is the same as the " k " of the id of the previous < div > to connect the control. Finally add onclick at the button to trigger the change function

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>Change</title>
		<style type="text/css">
			div{
				width:auto ;
				height: auto;
				margin-bottom: 20px;
				margin-left: 20px;
			}
		</style>
		<script>
			function change() {
				document.getElementById("k").style.border="5px double red"
			                  }
		</script>
	</head>
	<body>
		<div id="k">输入文字</div>
		<input type="button" value="change" onclick="change()"/>
	</body>
</html>

carry out
Insert picture description here

Published 18 original articles · Likes6 · Visits 1859

Guess you like

Origin blog.csdn.net/qq_43479203/article/details/101390796