How to quote/write JSP variable in JavaScript inline attribute code?

前端 未结 2 1781
太阳男子
太阳男子 2021-01-23 20:51

I need to send variables at runtime to a js method for ajax. I am trying with this onclick function but it gives syntax error on click.:



        
相关标签:
2条回答
  • 2021-01-23 21:34

    Spaces in your JavaScript code are most likely a syntax error. If your values have spaces, it's best to treat them as strings.

    onclick="sendAjax('${abc.firstVal}', '${abc.secVal}', ... '${abc.fifthVal}')">
    

    If you want to use them as numbers later, you can use the JavaScript functions parseInt and parseFloat to turn strings into numbers.

    0 讨论(0)
  • 2021-01-23 21:36

    Did you try leaving a space after the last curly brace?

    0 讨论(0)
提交回复
热议问题