JavaScript adds a dynamic effect to a Web page and enables the ability to interact with the user. Change color and height, hide or show content, cancel settings
<style type= "text/css" > Body{font-size:12px; }#txt{Height:200px;width:350px;Border:#333 solid 1px;padding:5px;Margin-bottom:20px; }P{Line-height:18px;text-indent:2em; }</style>
<DivID= "txt"> <h5>JavaScript adds a dynamic effect to a Web page and enables the ability to interact with the user.</h5> <P>111111111111111111111111111111111</P> <P>222222222222222222222222222222222</P> <P>333333333333333333333333333333333</P></Div><form> <!--when you click the appropriate button, do the corresponding action, add the corresponding event for the button - <inputtype= "button"value= "Change Color"OnClick= "ChangeColor ()" > <inputtype= "button"value= "Change the width of the height"OnClick= "Changewidth ()"> <inputtype= "button"value= "Hide Content"OnClick= "HideText ()"> <inputtype= "button"value= "Show content"OnClick= "Showtext ()"> <inputtype= "button"value= "Cancel Settings"OnClick= "Quexiao ()"></form>
<script type= "Text/javascript" >//define a function that "changes color" functionChangeColor () {varMyColor = document.getElementById (' txt '); Mycolor.style.color= ' Red '; Mycolor.style.backgroundColor= ' Gray '; } //define a function that "changes the width of the height" functionchangewidth () {varMywidth = document.getElementById (' txt ') Mywidth.style.width= ' 280px 'Mywidth.style.height= ' 280px ' } //functions that define "hidden content" functionHideText () {varMyChar = document.getElementById ("TXT"); Mychar.style.display= ' None '; } //functions that define "show content" functionShowtext () {varMychars = document.getElementById ("TXT"); Mychars.style.display= ' Block '; } //functions that define "Cancel settings" functionQuexiao () {varQuexiao = document.getElementById ("TXT"); varQX = Confirm ("Are you sure you want to cancel?" "); if(QX = =true) {Quexiao.removeattribute ("Style"); } }</script>
:
Some basic JavaScript exercises