Javascript 内部onclick函数不工作

Javascript 内部onclick函数不工作,javascript,Javascript,在这里,我正在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"

在这里,我正在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函数未启动,任何人都可以帮助我。

在代码中,您仅绑定事件。如果要启动它,请在绑定后触发它:

element.onclick=函数(e){
var div=document.getElementById(“消息”);
var div1=document.getElementById(“发送”);
var输入=document.createElement(“textarea”);
var按钮=document.createElement(“输入”);
setAttribute(“类型”、“提交”);
setAttribute(“值”、“发送”);
setAttribute(“id”,candidateId);
input.name=“post”;
input.maxLength=“500”;
input.cols=“30”;
input.rows=“10”;
div.appendChild(输入);//appendChild
div.appendChild(按钮);
控制台日志(按钮)

button.onclick=function(e){/->working fine是否需要自动触发
按钮。onclick
?手动单击send按钮时,代码工作正常。如果不工作,我将在java脚本中动态创建元素。