<! DOCTYPE HTML> <HTML> <head> <Meta charset = "UTF-. 8"> <title> novice tutorial (runoob.com) </ title> </ head> <body> <P> the JavaScript capable of directly writing HTML output stream: </ P> <Script> document.write ( "<h1 of> this is a header </ h1 of>" ); document.write ( "<P> this is a paragraph </ P>." ) ; </ Script> <P> You can use only HTML output stream <strong> document.write </ strong> . If you use it after the document has loaded (for example, in a function), will cover the entire document. </ P> </ body> </ HTML>
<! DOCTYPE HTML>
<HTML>
<head>
<Meta charset = "GBK">
<title> newbie tutorial (runoob.com) </ title>
</ head>
<body>
<h1> My first JavaScript < / h1>
<the p->
JavaScript can react to events. For example, a click on the button:
</ the p->
<the Button of the type = "the Button" onclick = "Alert ( 'Welcome!')"> Point I </ the Button>!
</ Body>
</ HTML>
<! DOCTYPE HTML> <HTML> <head> <Meta charset = "UTF-8"> <title> newbie tutorial (runoob.com) </ title> </ head> <body> <h1> my first paragraph the JavaScript </ h1 of> <P ID = "Demo"> the JavaScript to change the content of the HTML element. </ P> <Script> function myFunction () { X = document.getElementById ( "Demo"); // find the elements x.innerHTML = "the JavaScript the Hello!"; // change the content } </ Script> <Button type = "button" onclick = "myFunction ( )"> click here </ Button> </ body> <
<!DOCTYPE html> <html> <head> <meta charset="gbk"> <title>菜鸟教程(runoob.com)</title> </head> <body> <script> function changeImage() { element=document.getElementById('myimage') if (element.src.match("bulbon")) { element.src="E:/72.jpg"; } else { element.src="E:/0.jpg"; } } </script> <img id="myimage" onclick="changeImage()" src="E:/72.jpg" width="100" height="180"> <p>点击切换鲜花</p> </body> </html>
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>菜鸟教程(runoob.com)</title> </head> <body> <h1>我的第一段 JavaScript</h1> <p id="demo"> JavaScript 能改变 HTML 元素的样式。 </p> <script> function myFunction() { x=document.getElementById("demo") // 找到元素 x.style.color="#ff0000"; // 改变样式 } </script> <button type="button" onclick="myFunction()">点击这里</button> </body> </html>
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>菜鸟教程(runoob.com)</title> </head> <body> <h1>我的第一段 JavaScript</h1> <p>请输入数字。如果输入值不是数字,浏览器会弹出提示框。</p> <input id="demo" type="text"> <script> function myFunction() { var x=document.getElementById("demo").value; if(x==""||isNaN(x)) { alert("不是数字"); } } </script> <button type="button" onclick="myFunction()">点击这里</button> </body> </html>
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>菜鸟教程(runoob.com)</title> </head> <body> <h1>我的第一段 JavaScript</h1> <p>请输入数字。如果输入值不是数字,浏览器会弹出提示框。</p> <input id="demo" type="text"> <script> function myFunction() { var x=document.getElementById("demo").value; if(isNaN(x)||x.replace(/(^\s*)|(\s*$)/g,"")==""){ alert("不是数字"); } } </script> <button type="button" onclick="myFunction()">点击这里</button> </body> </html>