how to call onclick function on dynamically created button in javascript

前端 未结 4 1085
花落未央
花落未央 2021-02-14 21:45
var del = document.createElement(\'input\');
del.type = \'button\';
del.name = \'delll\';
del.value = \'del\';
del.onClick = \'alert(\"hi  javascript\")\';
4条回答
  •  Happy的楠姐
    2021-02-14 22:27

    del.onclick = function () {
        alert("hi  jaavscript");
    };
    

    Use small "C" in onClick and pass a function for it.

    Demo here

提交回复
热议问题