内置函数、JavaScript中的对象和JavaScript用户自定义对象

内置函数分为: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)

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值