[問題] 動態建立Element
<html>
<script type="text/javascript">
function mAlert() {
alert(this.value);
}
function mLoad(){
var obj = document.createElement("Input");
obj.type = "button";
obj.value = "btn";
obj.onclick = mAlert;
document.getElementById("div").appendChild(obj);
}
</script>
<body onload="mLoad()">
<input type="button" id="btn2" value="btn2" onclick="mAlert()">
<div id="div">
</div>
</body>
</html>
上頭的程式執行後,btn2印不出東西來,而btn就印的出來
是為什麼呢?
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 59.104.181.192
推
02/26 21:14, , 1F
02/26 21:14, 1F
→
02/26 21:15, , 2F
02/26 21:15, 2F
→
02/26 21:15, , 3F
02/26 21:15, 3F
→
02/26 21:17, , 4F
02/26 21:17, 4F
→
02/26 21:17, , 5F
02/26 21:17, 5F
→
02/26 21:18, , 6F
02/26 21:18, 6F
→
02/26 21:18, , 7F
02/26 21:18, 7F
→
02/26 21:19, , 8F
02/26 21:19, 8F
→
02/26 21:20, , 9F
02/26 21:20, 9F
→
02/26 21:22, , 10F
02/26 21:22, 10F
推
02/26 21:26, , 11F
02/26 21:26, 11F
→
02/26 21:27, , 12F
02/26 21:27, 12F
推
02/26 21:32, , 13F
02/26 21:32, 13F
→
02/26 21:33, , 14F
02/26 21:33, 14F
Ajax 近期熱門文章
PTT數位生活區 即時熱門文章