简体   繁体   中英

Assigning Freemarker variable in javascript

I want to assign a value inside javascript value

function abc(){
var b = document.getElementById("tc").value;
if(b=="true"){
<#assign x=true>
}
else{
<#assign x=false>
}
}

however I am not able to get value of x. Can someone please let me know how to assign freemarker variable inside javascript.

This cannot be done. Javascript is evaluated in the browser and FreeMerker is evaluated on the server before it gets to the browser. If you are generating the JS through FM such as in a script block of a html file then what the browser will see is

function abc(){
    var b = document.getElementById("tc").value;
    if(b=="true"){

    }
    else{

    }
}

You can verify this by looking at the source in the browser (for FireFox right click and select View Page Source).

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