O JS pode perceber que os usuários alteram o estilo na página selecionando condições na página. O estilo de página pode ser modificado através do estilo ou através de CSS. Vamos dar uma olhada no JS para mudar o estilo de estilo. O código é o seguinte:
<! Doctype html public "-// w3c // dtd html 4.01 transitória // pt"> <html> <head> <title> alteração.html </title> <meta http-equiv = "content-type" content = "text/html; charset = utf-8" type = "text/css" href = "./ styles.css">-> <script idioma = "javascript"> function test4 (event) {if (event.value == "preto") {// obtenha div1 var div1 = document.getElementById ('div1'); div1.style.backgroundColor = "Black"; } if (event.Value == "Red") {// Get div1 var div1 = document.getElementById ('div1'); div1.style.backgroundcolor = "vermelho"; }} </script> </adhead> <body> <div id = "div1"> div1 </div> <input type = "button" value = "preto" onclick = "test4 (this)"/> <input type = "button" value = "vermelho" onclick = "test4 (this)"/> </body> </html>O teste4 (this) representa o atual <entrada equivalente a tratá -lo como um objeto.
Vamos dar uma olhada em alterar o estilo CSS novamente, o código é o seguinte:
<! Doctype html public "-// w3c // dtd html 4.01 transitória // pt"> <html> <head> <title> alteração1.html </title> <meta http-equiv = "content-type"/"text/html; charset = uttps-8" href = "css/alteração.css"> <script linguage = "javascript"> function test4 (event) {// obtenha todos os seletores de classe na folha de estilo para obter var oCssRules = document.stylesheets [0] .RULES; // retire a classe var style1 = ocssrules [0]; if (event.value == "preto") {//window.alert(style1.style.backgroundcolor); style1.style.backgroundColor = "Black"; } else if (event.value == "vermelho") {style1.style.backgroundColor = "vermelho"; }} </script> </adhead> <body> <div id = "div1"> div1 </div> <input type = "button" value = "preto" onclick = "test4 (this)"/> <input type = "button" value = "vermelho" onclick = "test4 (this)"/> </body> </html>O exposto acima é o conteúdo inteiro dos exemplos simples de alterar os estilos de estilo e CSS trazidos a você pelo editor. Espero que todos apoiem mais wulin.com ~