chapter1
name:show the date
<html>
<head>
<script>
function displayDate()
{
document.getElementById("demo").innerHTML=Date();
}
</script>
</head>
<body>
<h1>a JavaScript programme </h1>
<p id="demo">this is a paragraph </p>
<button type="button" onclick="displayDate()"> show the date </button>
</body>
</html>
chapter2
name:#
<html>
<body>
<p>
Javascript can be written in HTML 输出流 directly
</p>
<script>
document.write("<h1> this is a title </<h1>");
document.write("<p> this is a paf </p>");
</script>
<p>
you can only use <strong> document.write </strong> in HTML输出流
if used in a document has been loadded (such as in a function) ,it will cover the whole document.
</p>
</body>
</html>
chapter3
name:reflect
<html>
<body>
<h1> my JavaScript </h1>
<p>
JavaScript can react to events,such as onclick a button
</p>
<button tpye="button" onclick="alert('welcome')"> click me </button>
</body>
</html>
chapter4
name:change
<html>
<body>
<h1> a Javascript </h1>
<p id ="demo">
JavaScript can change the HTML
</p>
<script>
function myFunction()
{
x=document.getElementById("demo");//find the element
x=innerHTML=" Hello JavaScript ";//change the content
}
</script>
<button type="button" onclick="myFunction()"> click here </button>
</body>
</html>
chapter5
name:turn on/off bulb
<html>
<body>
<script>
function changeImage()
{
element=document.getElementById('myimage')
if (element.src.match("button"))
{
element.src="/images/pic_bulboff.gif";
}
else
{
element.src="/images/pic_bulbon.gif";
}
}
</srcipt>
<img id="myimage" onclick="changeImage()"
src="/images/pic_bulboff.gif" width="100" height="180>
<p>click the bulb and turn on or turn off it </p>
</body>
</html>
chapter6
name:style
<html>
<body>
<h1> a JavaScript progarmme </h1>
<p id="dome">
JavaScript can change the style
</p>
<script>
function myFunction()
{
x=decument.getElementById("dome")//find the element
x=style.color="#ff0000";//change the style
}
</script>
<button type="button" onclick="myFunction()">click here </button>
</body>
</html>
chapter7
name:check the input
<html>
<body>
<h1> a JavaScript </h1>
<p> please put in the number if it's not a number ,the browser will remind you </p>
<input id="demo" type ="text">
<script>
function myFunction()
{
var x=document.getElmentById("demo").value;
if(x=="||isNAN(x))
{
alert(" it is not a number ");
}
}
</script>
<button type="button" onclick="myFunction()"> click here </button>
</body>
</html>
PS: a littel 渣渣 content
更多推荐
JavaScript菜鸟教程练习
发布评论