简体   繁体   中英

How to encode javascript function

How can i encode my parameters in javascript?

This my function and my parameter called newvalue

<script>
function selectChanged(newvalue) 
{
location.href="tester?restid=" + newvalue;
}
</script>

This is how i tried with adeneos suggestion

   window.location.href = "tester?restid=" + encodeURIComponent(newvalue);

but this does not work.

This is what i am getting:

tester?restid=38619

This is want i want

 tester%3Frestid%3D38619%21 
function selectChanged(newvalue)  {
    window.location.href = encodeURIComponent("tester?restid=" + newvalue);
}

尝试这个:

location.href="tester?restid=" +encodeURIComponent( newvalue );

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