js的三大作用
javascript可以用来做的三件最基础的事
1.改变html中的内容
2.改变html中的样式
3.对输入检测
下面是案例
<!DOCTYPE html> <html> <body> *************************************************************************************************** <h1>JavaScript Can Change Images</h1> <img id="myImage" onclick="changeImage()" src="pic_bulboff.gif" width="100" height="180"> <p>Click the light bulb to turn on/off the light.</p> *************************************************************************************************** <br> <h1>What Can JavaScript Do?</h1> <p id="demo1">JavaScript can change the style of an HTML element.</p> <button type="button" onclick="myFunction()">Click Me!</button> <br> *************************************************************************************************** <h1>JavaScript Can Validate Input</h1> <p>Please input a number between 1 and 10:</p> <input id="numb" type="number"> <button type="button" onclick="validate()">Submit</button> <p id="demo2"></p> <script> function changeImage() { var image = document.getElementById('myImage'); if (image.src.match("bulbon")) { image.src = "pic_bulboff.gif"; } else { image.src = "pic_bulbon.gif"; } } function myFunction() { var x = document.getElementById("demo1"); x.style.fontSize = "25px"; x.style.color = "red"; } function validate() { var x, text; // Get the value of the input field with id="numb" x = document.getElementById("numb").value; // If x is Not a Number or less than one or greater than 10 if (isNaN(x) || x < 1 || x > 10) { text = "Input not valid"; } else { text = "Input OK"; } document.getElementById("demo2").innerHTML = text; } </script> </body> </html>
相关推荐
nmgxzm00 2020-11-10
ifconfig 2020-10-14
hhanbj 2020-11-17
zfszhangyuan 2020-11-16
古叶峰 2020-11-16
一个智障 2020-11-15
jipengx 2020-11-12
81427005 2020-11-11
xixixi 2020-11-11
游走的豚鼠君 2020-11-10
苗疆三刀的随手记 2020-11-10
Web卓不凡 2020-11-03
小飞侠V 2020-11-02
帕尼尼 2020-10-30
爱读书的旅行者 2020-10-26
帕尼尼 2020-10-23
杏仁技术站 2020-10-23
淼寒儿 2020-10-22