Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/393.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何从javascript访问瓶子参数{{var}}?_Javascript_Python_Bottle - Fatal编程技术网

如何从javascript访问瓶子参数{{var}}?

如何从javascript访问瓶子参数{{var}}?,javascript,python,bottle,Javascript,Python,Bottle,我正在开发一个模板,该模板将包含在一个更大的模板中,由于某些原因,该模板不接受Javascript中的任何参数 如果参数是从html访问的,那么一切都很好。下面是一个例子: test.tpl: <p>from html: {{arg}}</p> <script type="text/javascript"> window.alert("from script "+{{arg}}); </script> 最终结果是,html中的参数显示良好:

我正在开发一个模板,该模板将包含在一个更大的模板中,由于某些原因,该模板不接受Javascript中的任何参数

如果参数是从html访问的,那么一切都很好。下面是一个例子:

test.tpl: 

<p>from html: {{arg}}</p>
<script type="text/javascript">
window.alert("from script "+{{arg}});
</script>
最终结果是,html中的参数显示良好:

from html: some value
但windows警报提供了一些奇怪的信息:

[object HTMLLIElement]

发生了什么?

正如@dandavis在评论中指出的,在javascript中引用参数的正确方法是将其放在引号中:

test.tpl: 

<p>from html: {{arg}}</p>
<script type="text/javascript">
window.alert("from script "+"{{arg}}");
</script>
如果没有引号,JavaScript实际上看到的是一个字符串,后跟一个名为some value的变量,该变量不能与字符串文字连接。这是我的原始代码在浏览器中的外观:

    window.alert("from script " + some value);

这是错误的

我想你需要引用JS文字。但是
“abc”+某些值
应该是语法错误。。。
from script some value
    window.alert("from script " + some value);