一.属性,方法和事件
属性是指对象包含的值,使用"对象名,属性名"的方式进行操作
document.myfrom.first.value
方法在代码里,使用"对象名,方法名()"来调用该对象的方法
alter(")=Window.alter(")
事件响应用户操作,完成交互,如OnClick,OnKeyDown
一般可以分为鼠标事件,键盘事件及其他事件
二.JavaScript中的对象
1.自定义对象
开发人员根据自己的需要而定义的新对象
2.JavaScript内置对象
JavaScript将一些常用功能预先定义成对象,用户可以直接使用,这就是内置对象。
如字符串对象,数学对象,日期对象,数组对象,正则表达式对象等。
3.浏览器内置对象
浏览器对象是浏览器根据系统当前的配置和所转载的页面为JavaScript提供的一系列可供使用的对象
三.创建自定义对象的方式
1.使用Object关键字创建对象
//使用object创t建
var student = new Object()
//给学生添加一些属性
student.stuId="1001"
student.stuName="张三"
student.className="移动五班"
student.sayHello=function(){
document.write("大家好")
}
student.sayHello()
document.write("该学生的学号:"+student.stuId+",姓名:"+student+",班级:"+student.className)
2.使用function关键字创建对象
function teacher(tid,name){
this.tid=tid
this.name=name
this.eat=function(){
document.write("吃饭")
}
}
var t1=new teacher("1","张三")
t1.eat()
document.write(t1.tid)
三.JavaScript内置对象
1.字符串对象
用于储存一系列字符,使用单引号或双引号包含
(1)用于存储一系列字符
(2)使用单引号或双引号包含
var name="河南"
var http="sx.hnhpit.com"
(3)可以使用索引访问字符串中任何的字符
var char = http[5];
(3)可以在字符串中使用引号
2.数学对象
用于获取各种数学常量及数学函数
四.登录系统
账号:<input type="text" name="" id="name" value=""/>
密码:<input type="text" name="" id="password" value=""/>
注册:<input type="button" name="" id="button" value="注册" onclick="str()"/>
<script type="text/javascript">
function str(){
var name=document.getElementById("name").value
var password=document.getElementById("password").value
var button=document.getElementById("button").value
if(name.length>10){
alert("您输入的用户名应小于10")
}else if(password.length>6||password.indexOf("@")==-1){
alert("您输入的密码应小于6并且必须包含@")
}else{
alert("用户注册成功")
}
str();
}
</script>