基础知识 | js在逃知识收录

获取input输入的值

input.value

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<input type="text">
		<button>搜搜</button>
		<script>
		const input=document.querySelector('input[type="text"]');
		const button=document.querySelector("button");
		button.addEventListener('click',function(){
			console.log(input.value);
		})
		
		</script>
	</body>
</html>

我在条件判断常出的错-合集

if不是结果为true才执行吗?

请记牢下面这段话:

代表空、否定的值都会被转换为false,比如" "、0、NaN、null、undefined

其他值都会被转为true

 

 

 

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<script>
			var a=4;
			// 你这里给a赋值为1,为正确的,等价于if(true),所以可以输出啊
			if(a=1){
				console.log(222);
			}
			// 当条件语句为true时,可以执行
			if(true){
				console.log(333);
			}
			// 当条件为false时,不能执行,无法打赢出444
			if(false){
				console.log(444);
			}
			// 你最开始的目的应该是判断值是不是等于4,你应该这样写
			// 记住 = 是赋值 ,==才是判断等不等
			var b = 4;
			if(b == 1){
				console.log("b的值等于1");
			}
			if(b == 4){
				console.log("b的值为4");
			}
			// 其余都会被转为true,下面这种也是true,所以可以被打印出来
			if(6){
				console.log(666);
			}
		</script>
	</body>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值