【问题标题】:jsp: javascript template literal not workingjsp:javascript模板文字不起作用
【发布时间】:2018-10-05 16:02:12
【问题描述】:

我尝试使用模板文字

预期结果是“测试数据测试”

但是,它不起作用

jsp上怎么用?

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<script>
var t = "TEST";

console.log(`테스트 데이터  ${t} `);
</script>
<body>

</body>
</html>

【问题讨论】:

  • console.log(TEST DATA ${t} );

标签: javascript java jsp ecmascript-6 template-literals


【解决方案1】:

关键点是'\'

console.log(`테스트 데이터  \${t} `);

【讨论】:

    【解决方案2】:

    你的代码有两个问题:

    首先,你需要使用"或'而不是 Then you need to can not set parameter in javascript side and get it via${t},due to${t}`是一个EL表达式

    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8">
    <title>Insert title here</title>
    </head>
    <% String t="TEST"; %> <!-- set value in the server side -->
    <script>
    console.log("테스트 데이터  ${t}");
    </script>
    <body>
    
    </body>
    </html>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-04-13
      • 1970-01-01
      • 2018-07-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多