When browsing some websites, especially some novel websites, there will be a place to modify the background color of the page. This function is easily implemented using jquery.
:
Show you code:
Copy codeThe Code is as follows:
<! Doctype html>
<Html>
<Head>
<Meta charset = "UTF-8">
<Title> jquery test </title>
<Script src = "jquery-1.11.1.min.js"> </script>
</Head>
<Body>
<Button style = "background-color: white" value = "white"> white </button>
<Button style = "background-color: red" value = "red"> red </button>
<Button style = "background-color: green" value = "green"> green </button>
<Button style = "background-color: yellow" value = "yellow"> yellow </button>
<Div class = "show">
</Div>
<Script>
$ ("Button"). click (
Function ()
{
Var color = this. value;
$ ("Body" ).css ("background-color", color );
}
)
</Script>
</Html>
Select the object to be operated: button Based on the element name, use the click method to find the clicked button, and then obtain the corresponding color value of the button in the trigger event, then, the color value is passed in as the property value of background-color through the css () method.