Escreva uma função para clicar no botão alterar para adicionar uma borda dupla vermelha ao elemento div.
Primeiro escreva um < div > em < body >
<body>
<div id="k">输入文字</div>
<input type="button" value="change"/>
</body>
A saída é
Depois que você os tiver, é possível definir o estilo css de < div > em < 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>
Depois de ter o estilo CSS, você pode usar os botões acima para controlar o estilo de < div > .O
mais importante é < script >
yon
<script>
function change() {
document.getElementById("k").style.border="5px double red"
}
</script>
O " k " aqui é o mesmo que o " k " do id da < div > anterior para conectar o controle.Finalmente, clique no botão para ativar a função de alteração
<!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>
Concluir