Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 按按钮改变行为?_Javascript - Fatal编程技术网

Javascript 按按钮改变行为?

Javascript 按按钮改变行为?,javascript,Javascript,当我按下“更改”按钮时,单击按钮1如何更改功能 <input type="button" value="button1" id="go" onclick='funcion()'\ > <input type="button" value="change" id="change"\ > 函数function(){ //第一个动作 } 函数newFunction(){ //第二个动作 } 在change按钮的单击处理程序中设置变量,并在function()中检查变量。能否

当我按下“更改”按钮时,单击按钮1如何更改功能


<input type="button" value="button1" id="go" onclick='funcion()'\ >
<input type="button" value="change" id="change"\ >
函数function(){ //第一个动作 } 函数newFunction(){ //第二个动作 }
change
按钮的单击处理程序中设置变量,并在
function()
中检查变量。能否提供有关您尝试执行操作的更多详细信息?你想改变什么行为?例如。。当我第一次按下按钮1时,向我显示一个提示“1”,然后我按下按钮“更改”,更改按钮1的功能。。改变其功能
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>