簡體   English   中英

改變按鈕行為?

[英]Changing behavior pressing a button?

<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>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM