js中排他思想

<body>

            

        <button type="button">按钮1

        </button>

        <button type="button">按钮2

        </button>

        <button type="button">按钮3

        </button>

        <button type="button">按钮4

        </button>

        <button type="button">按钮5

        </button>

        

        <script type="text/javascript">

            // 1.获取所有元素

            var btns = document.getElementsByTagName('button');

            // 2.btns得到的是伪数组  里面的每一个元素 btns[i]

            for (var i = 0; i < btns.length ;i++){

                btns[i].onclick = function(){

                    console.log(11);

                    // 1 我们先把所有的按钮背景颜色去掉

                    for(var i = 0; i < btns.length ;i++){

                        btns[i].style.backgroundColor = '';

                        // 2.然后才让当前的元素背景为pink

                        this.style.backgroundColor = 'pink';

                    }

                }

            }

        </script>

Math对象

// Math和其它对象不同,不是构造函数,是工具类,封装了数学运算相关属性和方法
			console.log(Math.PI)
			console.log(Math.abs(-100))
			console.log(Math.ceil(1.4))
			console.log(Math.floor(1.4))
			console.log(Math.round(1.4))
			console.log(Math.random())
			console.log(Math.round(Math.random()*10))
			console.log(Math.max(40,20,15,50));
			console.log(Math.min(40,20,15,50));
			console.log(Math.pow(2,3));
			console.log(Math.sqrt(16));

Date对象 

//Date对象用来表示一个时间 
			// 如果直接使用构造函数创建一个Date对象,会封装为当前代码执行时间
			var d = new Date();
			console.log(d)
			// 日期格式 月/日/年 时:分:秒
			var d2 = new Date("1/1/2000 1:11:11")
			console.log(d2)
			
			
			// getTime()获取时间戳
			var date = d2.getTime()
			console.log(date)
			// Date.now()获取当前时间戳
			date = Date.now()
			console.log(date)

包装类

// js中为我们提供了三个包装类,这三个包装类可将基本数据类型转换为对象Object
			// String()
			// Number()
			// Boolean()
			
			var num = new Number(3);
			console.log(typeof num)
			
			num.name = "test"
			console.log(num)
			// 在实际应用中不会使用基本数据类型的对象,如下
			var b = new Boolean(false)
			if(b){
				console.log("运行")
			}
			
			// 方法和属性只能添加给对象,不能添加给基本数据类型
			// 对基本数据类型的值去调用属性和方法时,浏览器会将其临时使用包装类转换为对象
			var s = 123;
			s = s.toString();
			// 没有报错,说明转换为对象
			s.name = "test";
			// 输出undefined,说明转换为了基本数据类型
			console.log(s.name)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值