Calling multiple JavaScript functions on a button click

前端 未结 11 1633
灰色年华
灰色年华 2020-12-23 22:37

How to call multiple functions on button click event?

Here is my button,



        
11条回答
  •  甜味超标
    2020-12-23 23:40

    Because you're returning from the first method call, the second doesn't execute.

    Try something like

    OnClientClick="var b = validateView();ShowDiv1(); return b"
    

    or reverse the situation,

    OnClientClick="ShowDiv1();return validateView();"
    

    or if there is a dependency of div1 on the validation routine.

    OnClientClick="var b = validateView(); if (b) ShowDiv1(); return b"
    

    What might be best is to encapsulate multiple inline statements into a mini function like so, to simplify the call:

    // change logic to suit taste
    function clicked()  {
        var b = validateView(); 
        if (b) 
            ShowDiv1()
        return b;
    }
    

    and then

    OnClientClick="return clicked();"
    

提交回复
热议问题