JavaScript菜鸟教程练习

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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值