码迷,mamicode.com
首页 > Web开发 > 详细

JS基础知识

时间:2014-12-31 14:14:51      阅读:210      评论:0      收藏:0      [点我收藏+]

标签:

JavaScript事件列表

一般事件:主要是鼠标擦偶偶

页面事件:onload(页面内容完成时触发此事件)、onmove(浏览器窗口被移动)、onresize(浏览器窗口大小改变)、onstop(浏览器停止按钮被按下或正在下载的文件被中断)、onabort(在下载时被用户中断)

表单事件:onsubmit(表单事件被触发时提交)

 

JavaScript常用内部对象

Object 提供自定义对象,不需要定义构造函数

String 动态对象,只有创建实例后,才能引用其属性和方法

           ----------------- length、indexOf、replace、substr(返回指定位置,指定长度)、substring(返回从一个开始位置到另一个结束位置间的所有字符串)、toLowerCase、toUpperCase

Array 创建数组,可对其进行排序、删除等操作

Document 该对象是与文档元素(element)一起工作的对象  

          ----------------write、writeln(与write相似,但输出文本随后空一格)、open(清除当前文档,写入指定类型数据流)、close(关闭文档输入流)

 

1、定时器相关知识

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
 

</head>

<body onload="progress_update()">
<div id="demo" style="border:solid #0000FF 2px"></div>

<script type="text/javascript">

 var prosressInterval=60;
 var progressBegin=0;
 var  progressEnd=30;
 var progressTimer;
 function progress_clear()
 {
     //清空定时器
     clearTimeout(progressTimer);
     //隐藏div
     document.getElementById("demo").style.visibility="hidden";
 }
 function progress_update()
 {
     progressBegin++; 
    if(progressBegin>progressEnd)
    //progress_clear(); 
     clearTimeout(progressTimer);
    else
        // document.getElementById("demo").style.backgroundColor="blue";
        document.write("<br>"+progressBegin+" ");
    progressTimer=setTimeout("progress_update()",prosressInterval); 
 }
</script>
</body>
</html>

2、函数相关知识

这个例子主要是举了创建Student类的属性、方法,以及其调用方法

var obj=new objName(参数);

for(var property in student)
{ 
alert(flag+property+" "+student[property]);
}

可用以上的方法查看student中各个属性和方法

<!DOCTYPE html>
<head></head>
<body onload="progress_update()">
<div id="demo" style="border:solid #0000FF 2px"></div>
<div>
<input id="txt1" type="text"  />
<input id="txt2" type="text"  />
<input id="but1" type="button" onclick="Study()"  />
</div>

<script type="text/javascript">
//自定义函数
//function 函数名(参数)
//{code;return expression;}
//对象的创建
function Student(name,age)
{
this.name=name;
this.age=age;
this.Read=Read;//注意调用方法Read()这个用法
}
function Read()
{
alert(this.name+"正在读书");
}
function Study()
{
var student=new Student(txt1.value,txt2.value);
student.Read();
} 
</script>
</body>
</html>

 注意:

1、要着重掌握好string的基本用法

2、计时器很可能会用到

3、document.write("content"),document.getElementById("id")

4、js中区分字母大小写,注释、基本语法与C系语言相同

JS中innerHTML,innerText,value  的区别

 

JS基础知识

标签:

原文地址:http://www.cnblogs.com/songxxu/p/4195428.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!