javascript动态添加button,并添加onclick事件
<script type="text/javascript">
function CreatButton() {
var btn = document.createElement("input");
btn.type = "button";
btn.style.width = "80px";
btn.id = "submit";
btn.name = "submit";
btn.value = "发送";
btn.onclick = "submit()";
document.getElementById("mydiv").appendChild(btn);
}
function submit() {
alert("111");
}
</script>
为什么点击生成的button没有反应呢?
在线急等,求大神帮忙!
------解决方案--------------------btn.onclick =submit;
或
btn.onclick = function () { submit(); };