内置函数分为:parseint()函数、parse Float()函数和isNaN()函数
使用函数运算:
<body>
第一个数:<input type="text" name="" id="one" value=""/><br />
第二个数:<input type="text" name="" id="two" value=""/><br />
运算方式:<input type="button" name="" id="" value="+" onclick="cal_1('+')" />
<input type="button" name="" id="" value="-" onclick="cal_1('-')" />
<input type="button" name="" id="" value="*" onclick="cal_1('*')"/>
<input type="button" name="" id="" value="/" onclick="cal_1('/')"/><br />
运算结果:<input type="text" name="result" id="result" value="" />
<script type="text/javascript">
function cal_1(y){
//实现两个数的相加
//获取文本框的值
var one = document.getElementById("one").value
var two = document.getElementById("two").value
var result = 0
if(y=="+"){
result=parseFloat(one)+parseFloat(two)
}else if(y=="-"){
result=parseFloat(one)-parseFloat(two)
}else if(y=="*"){
result=parseFloat(one)*parseFloat(two)
}else if(y=="/"){
result=parseFloat(one)/parseFloat(two)
}
document.getElementById("result").value=result
}
</script>
</body>
属性:属性是指对象包含的值,使用‘对象名.属性名’的方式进行操作,如document.myfrom.first.value
方法:在代码里,使用‘对象名.方法名()’来调用该对象的方法
alter(")=Window.alter(")
事件:影响用户操作、完成交互,如OnClick、OnKeyDown
一般可以分为鼠标事件、键盘事件及其他事件
自定义对象:开发人员根据自己的需要而定义的新对象
//自定义对象的创建
//使用Object创建一个对象
var student=new Object()
//console.log(student)
//给对象student添加属性stuID、stuName、className
student.stuID="1001"
student.stuName="张三"
student.className="移动2班"
//给对象添加一个函数sayHello()
student.sayHello=function(){
console.log("大家好")
}
对象名.函数名()实现函数的调用
student.sayHello()
console.log(student.stuID)
console.log(student.stuName)
console.log(student.className)
使用funtcion创建一个函数
function teacher(tid,tname){
//this表示当前对象
this.tid=tid//教师编号
this.tname=tname//教师姓名
this.eat=function(){//行为
console.log("吃饭")
}
}
var t1=new teacher("1","张三")
使用t1来访问属性和函数
//调用函数
t1.eat()
console.log(t1.tid,t1.tname)