相关疑难解决方法(0)

添加onclick事件动态添加按钮?

我在html中动态添加一个按钮,如下所示:点击该按钮,我想调用一个Javascript函数:

var but = document.createElement("button");

but.value="delete row";

but.setAttribute("onclick","callJavascriptFunction()");
//this is not working

but.onclick="callJavascriptFunction()"
//this is also not working

document.getElementById("but").onclick="callJavascriptFunction()"
//this is also not working

but.id="but"+inc;
Run Code Online (Sandbox Code Playgroud)

有没有办法解决这个问题?Plz帮助我.,提前谢谢

html javascript forms

13
推荐指数
5
解决办法
11万
查看次数

标签 统计

forms ×1

html ×1

javascript ×1