Using multiple buttons on same function that redirects to different functions

后端 未结 4 988
暗喜
暗喜 2020-12-09 21:24

So..i\'m having this problem for couple of days not knowing how to do this,and i need help.

I have multiple buttons and clicking all of them is redirecting me to sam

4条回答
  •  时光说笑
    2020-12-09 22:03

    IF you can change the HTML, try:

    
    
    
    

    And change your JS to:

    function myFunction(bnum)
    {
       var x=0;
    
        if (bnum == 1){
         x=1;
         myFunction1(x);}
    
       if (bnum == 2){
        x=2;
        myFunction2(x);}
    
        if (bnum == 3){
         x=3;
         myFunction3(x);}
    }
    

    It's a bit nicer in a switch:

    function myFunction(bnum)
    {
       var x=0;
       switch (bnum) {
          case 1:
              x = 1;
              myFunction1(x);
          break;
          case 2:
              x = 2;
              myFunction1(x);
          break;
          case 3:
              x = 3;
              myFunction1(x);
          break;
       }
    }
    

提交回复
热议问题