我在这里创造的onclick函数内部的onclick现在的工作内部的onclick功能不能正常工作
element.onclick = function(e) {
var div = document.getElementById("message");
var div1= document.getElementById("send");
var input = document.createElement("textarea");
var button = document.createElement("input");
button.setAttribute("type", "submit");
button.setAttribute("value", "send");
button.setAttribute("id", candidateId);
input.name = "post";
input.maxLength = "500";
input.cols = "30";
input.rows = "10";
div.appendChild(input); //appendChild
div.appendChild(button);
console.log(button)
button.onclick = function(e) {
alert("comming")
}
}
这里button.onclick功能不开火,任何一个可以帮助我..
https://jsfiddle.net/arunpjohny/g1d26gfL/1/ - >工作正常 –
是否需要自动触发'button.onclick'?手动点击发送按钮时,代码工作正常。 – Munawir
不工作,我在Java脚本中也动态创建元素。 – arjun