简体   繁体   中英

Javascript onClick function with parameters

I have a Javascript function as below:

function letMeGo(var1, var2, var3){
    if(var1 == 1 && var2 == 1 && var3 == 1){
        document.getElementById('goOn').href="goOn.php";
    }
}

the variables are the return of other functions.

And I need it to be triggered by:

<a id="goOn" onclick="letMeGo(var1, var2, var3)">Go On</a> 

it is not working unless I removed the variable in both, the link and the function. How can i get it to work with them?

you have to affect the return of the other functions to global variables (example: window.myvar1 ) and use them instead of your parameters var1, var2, var3 .

I mean to not use any parameters in your function letMeGo and inside it, replace var1 by its global variable equivalent, and so on for var2 and var3.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM