how to call onclick function on dynamically created button in javascript

前端 未结 4 1067
花落未央
花落未央 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条回答
  •  无人共我
    2021-02-14 22:12

    Try like this

        var del = document.createElement('input');
        del.setAttribute('type', 'button');
        del.setAttribute('name', 'delll');
        del.setAttribute('value', 'del');
        del.setAttribute('onClick', 'alert("hi  jaavscript")');
    

提交回复
热议问题