0
<input type="button" value="button1" id="go" onclick='funcion()'\ >
<input type="button" value="change" id="change"\ >
当我按下按钮更改时,如何更改按钮1中的OnClick函数?按下按钮更改行为?
<input type="button" value="button1" id="go" onclick='funcion()'\ >
<input type="button" value="change" id="change"\ >
当我按下按钮更改时,如何更改按钮1中的OnClick函数?按下按钮更改行为?
document.getElementById("change").onclick = function() { // when clicking #change
document.getElementById("go").onclick = function() { // overide the click event listener of #go
// ...
}
}
<input type="button" value="button1" id="go" onclick='funcion()'\ >
<input type="button" value="change" id="change" onclick='funcion=newFuncion'\>
<script>
function funcion() {
//first action
}
function newFuncion() {
//second action
}
</script>
设置在'change'按钮的点击处理程序的变量,并检查变量'funcion()'。 – Barmar
你能否提供更多关于你想要做什么的细节?你想改变什么行为?例如 – Barmar
..第一次当我按下按钮1显示我的警告“1”,然后我按按钮“改变”,改变button1做什么..改变它的功能 –