高手就能够直接跳过了,刚開始学习javascript,从零開始, 记录一点一滴,不断提高。
菜鸟的不断成长。
以下就写上几个简单的JS 入门代码吧。高手就不要BS了
<!DOCTYPE html> <html> <body> <script> function changeImage(){ element=document.getElementById("myimage") if(element.src.match("bulbon")){ element.src="i/eg_bulboff.gif"; }else{ element.src="i/eg_bulbon.gif"; } } </script> <img id="myimage" onclick="changeImage()" src="i/eg_bulboff.gif" /> </body> </html>
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Insert title here</title> </head> <body> <h1>Jscript样例1</h1> <p id="demo"> hello world.welcome to here. </p> <script type="text/javascript"> function myf(){ x=document.getElementById("demo"); x.innerHTML="你好,PPKER。欢迎来到JS"; } </script> <input type="button" onclick="myf()" value="点击"> </body> </html>
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Insert title here</title> </head> <body> <h1>改变样式</h1> <p id="demo"> 德玛上单,不给就送啊! </p> <script type="text/javascript"> function myf(){ x=document.getElementById("demo"); x.style.color="red"; } </script> <input type="button" onclick="myf()" value="点击"> </body> </html>
<!DOCTYPE html> <html> <head><meta charset="utf-8" /></head> <body> <input id="demo" type="text"> <script type="text/javascript"> function myf() { var x=document.getElementById("demo").value; if(x==""||isNaN(x)) { alert("姐,请输入数字"); }else{ alert("OK"); } } </script> <button type="button" onclick="myf()">点击这里</button> </body> </html>
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Insert title here</title> <script type="text/javascript"> function myf(){ document.getElementById("demo").innerHTML="~~~上MISS了,嘿嘿嘿"; } </script> </head> <body> <p id="demo">努克萨斯</p> <button type="button" onclick="myf()">点击</button> </body> </html>高手就不要BS了,都是从菜鸟開始的。别总是在想怎样学好,坚持下去吧。无他,唯孰而已。