获取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>