JavaScript的学习入门整理篇第1/3页
更新时间:2008年09月24日 23:22:09 作者:
每次刚开始学语言时,作者都喜欢用“hello world”例子l来侮辱我们的智商,我想大家都不是笨蛋,故而寥寥数笔写了一点
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=gb2312">
<title>Document.writeln()方法</title>
<script language="javascript">
function createsummary()
{
win2=open("","window2")
//win2.document.open("text/plain")
win2.document.writeln("title"+document.title)
win2.document.close()
}
</script>
</head>
<body>
<a name="#top"></a>
<form>
<input type="button" name="help" value="help"onClick="createsummary()">
</form>
<body>
</html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=gb2312">
<title>Document.writeln()方法</title>
<script language="javascript">
function createsummary()
{
win2=open("","window2")
//win2.document.open("text/plain")
win2.document.writeln("title"+document.title)
win2.document.close()
}
</script>
</head>
<body>
<a name="#top"></a>
<form>
<input type="button" name="help" value="help"onClick="createsummary()">
</form>
<body>
</html>
说一下知识要点吧:
1:JavaScript是一种区分大小写的语言。
2:建议每写一行要用‘;';
3:命名第一个字母必须是字母、下划线或‘$';
4:在JavaScript中声明变量用var,而且是永久性的;
5:没有块级作用域。例如:
Var scope="globle";
function f(){
alert(scope); //显示“underfined"而不是"globle"
Var scope="local";
alert(scope);
}
F();
function f(){
alert(scope); //显示“underfined"而不是"globle"
Var scope="local";
alert(scope);
}
F();
Var scope="globle";
function f(){
Var scope;
alert(scope); //显示“underfined"而不是"globle"
Var scope="local";
alert(scope);
}
F();
function f(){
Var scope;
alert(scope); //显示“underfined"而不是"globle"
Var scope="local";
alert(scope);
}
F();
建议:将所有的变量声明集中起来放置在函数的开头是一个很好的编程习惯。
6:ECMAScript标准中规定函数不能重载,例如
function doadd(i){
alert(i);
}
function doadd(i){
alert(i);
}
doadd(10);
alert(i);
}
function doadd(i){
alert(i);
}
doadd(10);
真正执行的是后一个函数,第二个覆盖了第一个函数;
7:arguments对象的使用。
function doAdd()
If(arguments.length==1){
alert(arguments[0]+10);
}
If(arguments.length==2){
alert(arguments[0]+arguments[0);
}
doAdd(10);
doAdd(10,20);
If(arguments.length==1){
alert(arguments[0]+10);
}
If(arguments.length==2){
alert(arguments[0]+arguments[0);
}
doAdd(10);
doAdd(10,20);
运行效果:略……
相关文章
JavaScript Math.floor方法(对数值向下取整)
这篇文章主要介绍了Math.floor 方法用于对数值向下取整,即得到小于或等于该数值的最大整数,需要的朋友可以参考下2015-01-01
javascript使用window.open提示“已经计划系统关机”的原因
这篇文章主要介绍了javascript使用window.open提示“已经计划系统关机”的原因,本文得出结论是安装了系统更新或其它原因,要把系统重启时才会提示这个问题,所以,遇到这个问题,重启你的电脑吧2014-08-08
深入理解JavaScript系列(36):设计模式之中介者模式详解
这篇文章主要介绍了深入理解JavaScript系列(36):设计模式之中介者模式详解,中介者模式(Mediator)是指用一个中介对象来封装一系列的对象交互,需要的朋友可以参考下2015-03-03


最新评论