【问题标题】:${} template literal (ES2015) is work under jsp pages${} 模板文字(ES2015)在 jsp 页面下工作
【发布时间】:2019-10-28 12:20:47
【问题描述】:

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<meta http-equiv="X-UA-Compatible" content="ie=edge">
	<title>Document</title>
	
</head>
<body>
	<h2> why ${variableName} is in consider as undefined in jsp page
	<script>
		let x="x";
		console.log(`${x} is the variable`)

	</script>
</body>
</html>

${} 在 jsp 页面中被视为未定义。 请告诉我它是怎么来的。 谢谢!

【问题讨论】:

  • 您应该始终查看生成的 HTML,这很明显。

标签: javascript jsp ecmascript-5


【解决方案1】:

修复方法是使用反斜杠转义 ${myVar},以便 JSP 忽略它:

//my.jsp
<script>
   var n = "Dave";
   var s = `Hello \${n}`;  //note the backslash
</script>

【讨论】:

    猜你喜欢
    • 2017-01-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-20
    • 2015-11-11
    • 2013-09-25
    • 1970-01-01
    相关资源
    最近更新 更多