js can realize that users change the style in the page by selecting conditions in the page. The page style can be modified through style or through css. Let’s take a look at js to change the style style. The code is as follows:
<!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 == "black") { //Get div1 var div1 = document.getElementById('div1'); div1.style.backgroundColor="black"; } if(event.value == "red") { //Get div1 var div1 = document.getElementById('div1'); div1.style.backgroundColor="red"; } } </script></head><body> <div id="div1">div1</div> <input type="button" value="black" onclick="test4(this)"/> <input type="button" value="red" onclick="test4(this)"/> </body></html>test4(this) represents the current <input equivalent to treating it as an object.
Let’s take a look at changing the css style again, the code is as follows:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html> <head> <title>Change1.html</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" type="text/css" href="css/Change.css"> <script language="javascript"> function test4(event) { //Get all class selectors in the style sheet to get var ocssRules = document.styleSheets[0].rules; //Take out the class var style1 = ocssRules[0]; if(event.value == "black") { //window.alert(style1.style.backgroundColor); style1.style.backgroundColor="black"; }else if(event.value == "red") { style1.style.backgroundColor="red"; } } </script></head><body> <div id="div1">div1</div> <input type="button" value="black" onclick="test4(this)"/> <input type="button" value="red" onclick="test4(this)"/> </body></html>The above is the entire content of the simple examples of changing the style and css styles brought to you by the editor. I hope everyone will support Wulin.com more~