求解!原生js创建select后 打印不出来
<!DOCTYPE html><html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>1</title>
</head>
<body>
<div id="mm">
<script>
var select_d = document.createElement("select");
select_d.id = "select_d";
select_d.style.width = "200px";
select_d.style.height = "50px";
select_d.style.borderRadius = "10px";
select_d.style.position = "absolute";
select_d.style.top = "130px";
select_d.style.left = "65px";
select_d.style.display = "block";
var op1 = document.createElement("option");
op1.value = "Choose the dimension ";
op1.innerText = "Choose the dimension ";
select_d.appendChild(op1);
var op2 = document.createElement("option");
op2.value = "M1";
op2.innerText = "M1";
select_d.appendChild(op2);
mm.appendChild(select_d);
var obj = document.getElementById("Select_d");
console.log(select_d);//可以打印
console.log(obj); //打印不出来 null
</script>
</div>
</body> var obj = document.getElementById("Select_d");
改为
var obj = document.getElementById("select_d");
试试吧
你上面建的是小写的
页:
[1]