Changing button text onclick

后端 未结 18 2508
野性不改
野性不改 2020-11-27 03:10

When I click on myButton1 button, I want the value to change to Close Curtain from Open Curtain.
HTML:

<         


        
18条回答
  •  攒了一身酷
    2020-11-27 03:45

    It seems like there is just a simple typo error:

    1. Remove the semicolon after change(), there should not be any in the function declaration.
    2. Add a quote in front of the myButton1 declaration.

    Corrected code:

    
    ...
    function change()
    {
        document.getElementById("myButton1").value="Close Curtain"; 
    }
    

    A faster and simpler solution would be to include the code in your button and use the keyword this to access the button.

    
    

提交回复
热议问题