【js实验一、二】
1.编写一个JavaScript程序,实现在页面上输出“欢迎访问我的个人主页”,效果如图所示
<body>
<script type="text/javascript">
document.write("<hr />");
document.write("<h1>欢迎访问我的个人主页</h1>")
document.write("<hr />");
</script>
</body>
2.编写一个JavaScript程序,效果如图所示。
<body>
<script type="text/javascript">
var name = prompt("What's your name?");
var demanding = "can";
var tech = "dance";
var techy = name+" "+demanding+" "+tech;
document.writeln(techy);
</script>
</body>
3.编写一个JavaScript程序,效果如图所示。
<body>
<script type="text/javascript">
var name = prompt("你的名字是?");
var demanding = "会";
var tech = "唱歌。";
var techy = name+demanding+tech;
document.writeln(techy);
document.writeln(techy.bold())
document.writeln(techy.fontcolor('red'));
</script>
</body>
4.按要求实现如下界面:
其中var a=1;var b=2; var c=3;(alert弹出对话框)
<body>
<script type="text/javascript">
var a = 1;
var b = 2;
var c = 3;
alert("a+b-c的运算结果为:"+(a+b-c));
</script>
</body>
5.
<body>
<pre>
<script type="text/javascript">
var a = 2009;
var b = "相信明天会更好",result;
var c = true;
document.writeln("a=2009,b='相信明天会更好',c=true");
document.writeln("");
document.write("a+b=");result=a+b;document.writeln(result);
document.write("b+a=");result=b+a;document.writeln(result);
document.write("b+c=");result=b+c;document.writeln(result);
document.write("c+b=");result=c+b;document.writeln(result);
document.write("a+b+c=");result=a+b+c;document.writeln(result);
</script>
</pre>
按要求实现如下界面:
其中a=1 b=2
<body>
<script type="text/javascript">
var a = 1;
var b = 2;
var c = 0;
document.writeln("a=1,b=2<br />");
document.write("a+=b = ");result=a+=b; document.writeln(result);
document.write("b+=a = ");result=b+=a; document.writeln(result);
document.write("a-=b = ");result=a-=b; document.writeln(result);
document.write("b*=a = ");result=b*=a; document.writeln(result);
</script>
</body>
7.设计一个程序,小高今年22岁,应用条件判断语句,大于18岁就是成年人,否则为未成年人,并输出结果。
<body>
<script type="text/javascript">
var age = 22;
if (age>=18) {
alert("成年人");
} else{
alert("未成年人");
}
</script>
</body>
8.按要求实现如下界面:(alert弹出对话框)
其中a=1+2*3, b=(1+2)*3
<body>
<script type="text/javascript">
var a = 1+2*3;
var b = (1+2)*3;
alert("a="+a+"\nb="+b);
</script>
</body>
9.设计一个程序,返回true的数据类型。
<body>
<script type="text/javascript">
var a = true;
document.writeln(typeof(a));
</script>
</body>
10.输入一个四位年份,判断是否为闰年
<body>
<script type="text/javascript">
var year = prompt("请输入一个四位年份");
if (year%4==0&year%100!=0||year%400==0) {
alert("是闰年")
} else{
alert("不是闰年")
}
</script>
</body>