javascript to create a button with onclick

前端 未结 2 1829
你的背包
你的背包 2020-12-01 09:49

I\'m trying to use javascript to create a button that has a onclick event that calls a function defined in the head that takes in as parameter a dom object relative to the

2条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-01 10:14

    You can also use the built-in setAttrbute javascript function.

    var newButton = document.createElement("button")
    newButton.setAttribute("onclick", "blah(this.parentNode.value)")

    Hope it will help

提交回复
热议问题