javaScript技术

JavaScript

js数组

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>测试 js数组</title>
		<script>
			/* 方式一 */
			let a = new Array();
			a = new Array(1,1.6,true,'hello',null);
			a[98] = 0
			console.log(a);
			console.log(a.length);
			console.log(a[3]);
			console.log(a[a.length-1])
			/* 方式二*/
			let b = [];
			b = [1,2.8,false,'hi',null];
			console.log(b);
			console.log(b.length);
			console.log(b[3])
			for(let i = 0; i < b.length; i++){
				console.log(b[i] + "_+_+_+_+_")
			}
			for(var i in b){
				console.log(i);
				console.log(b[i]);
			}
		</script>
	</head>
	<body>
	</body>
</html>

js函数

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>JS函数及调用</title>
		<script>
			/* 方式一fanction function() */
			function cal(){
				console.log("cal的方法")
			}
			/* 方法二var function  = function() */
			var write = function(){
				console.log("write的方法")
			}
			cal();
			write();
			
			function fun(){ 
				var y = 0;
				for (var i = 1; i < 101; i++) {
				    if(i % 2 == 0){//过滤偶数
						y += i ;//求和
					}
				}
				return y;
			}
		</script>
	</head>
	<body>
		<button onmouseenter="fun()">fun的方法</button>
	</body>
</html>

js对象

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>第一遍JS对象</title>
		<script>
			/* 方式一 */
			function Person(){
			}
			let p = new Person();
			p.name="tony";
			p.addr="北京";
			console.log(p.name+p.addr);
			p.eat=function(){
				console.log("吃大餐")
			}
			console.log(p);
			p.eat();
			
			function a(){
				window.alert('100');	/* 弹出框 */
				window.confirm('确认');	/* 确认框 */
				window.prompt("请输入"); /* 输入框 */
				window.document;	/* 属性,获取网页文档 */
				var x = 'hello';
				console.log(x.length);
				console.log(x.charAt(0));
				console.log(x.concat('拼接'));
				console.log(x.substring(1,3));
			}
			
		</script>
	</head>
	<body>
	</body>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值